码迷,mamicode.com
首页 > Windows程序 > 详细

HDU 1509 Windows Message Queue

时间:2017-05-02 11:49:49      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:include   using   als   cstring   cpp   long   ace   operator   name   

水题。用来熟悉优先队列。


有两个键,一个是优先级。一个是ID。按优先级排。优先级一样就按ID排。


#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<vector>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define debug puts("==fuck==")
#define acfun std::ios::sync_with_stdio(false)

#define SIZE 20+10
using namespace std;
struct lx
{
    char str[101];
    int s;
    int value;
    int ID;
    friend bool operator <( lx a,lx b)
    {
        if(a.value==b.value)
            return a.ID>b.ID;
        return a.value>b.value;
    }
};
int main()
{
    priority_queue<lx> pq;

    char head[11];
    int Id=0;
    while(scanf("%s",head)!=EOF)
    {
        if(strcmp(head,"GET")==0)
        {
            if(pq.empty())
                puts("EMPTY QUEUE!");
            else
            {
                lx now;
                now=pq.top();
                pq.pop();
                printf("%s %d\n",now.str,now.s);
            }
        }
        else if(strcmp(head,"PUT")==0)
        {
            lx now;
            scanf("%s%d%d",now.str,&now.s,&now.value);
            now.ID=Id++;
            pq.push(now);
        }
    }
}


HDU 1509 Windows Message Queue

标签:include   using   als   cstring   cpp   long   ace   operator   name   

原文地址:http://www.cnblogs.com/wgwyanfs/p/6795137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!