hdu 1509 Windows Message Queue(优先队列)

来源:互联网 发布:网站美工 编辑:程序博客网 时间:2024/06/06 00:34

拾起以前丢下的!

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

这题最基本的优先队列!

#include<stdio.h>

#include<string.h>
#include<queue>
using namespace std;
struct node
{
int x,num,im;
char name[500];
friend bool operator<(node a,node b)
{
if(a.im!=b.im)
return a.im>b.im;
return a.num>b.num;
}
};


int main()
{
int i=0;
char str[5000];
node cur;
priority_queue<node>q;
while(scanf("%s",str)!=EOF)
{
if(strcmp("GET",str)==0)
{
if(q.empty())
printf("EMPTY QUEUE!\n");
else
{
cur=q.top();
q.pop();
printf("%s %d\n",cur.name,cur.x);
}
}
else
{
scanf("%s %d %d",cur.name,&cur.x,&cur.im);
cur.num=i++;
q.push(cur);
}
}
return 0;

}

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509
















原创粉丝点击