HDU 1509 Windows Message Queue(优先队列)

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=40702

代码:

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>

using namespace std;

struct node
{
    char name[33];
    int mes;
    int val;
    int num;
    friend bool operator<(node n1,node n2)
    {
        if(n1.val!=n2.val) return n1.val>n2.val;                //小的先出队
        return n1.num>n2.num;
    }
};

int main()
{
    priority_queue<node>q;
    node cur,next;
    int k=1;
    char str[55];
    while(~scanf("%s",str))
    {
        if(strcmp(str,"GET")==0)                //新技能GET
        {
            if(!q.empty())
            {
                cur=q.top();
                q.pop();
                printf("%s %d\n",cur.name,cur.mes);
            }
            else
                printf("EMPTY QUEUE!\n");
        }
        else
        {
            scanf("%s%d%d",next.name,&next.mes,&next.val);
            next.num=k++;
            q.push(next);
        }
    }
}



你可能感兴趣的:(HDU 1509 Windows Message Queue(优先队列))