您的位置:首页 > 产品设计 > UI/UE

hdu1509 Windows Message Queue

2015-07-28 15:33 483 查看
本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509

本题运用优先队列来解决,并运用了结构体的一些知识,AC代码如下:

#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
struct node{
char name[100];
int x,y;
int num;
friend bool operator < (node a,node b)
{
if(a.y!=b.y)
return a.y>b.y;
else return a.num>b.num;
}
};
int main()
{
priority_queue <node> q;
char a[100];
int count=1;
node Q;
while(scanf("%s",a)!=EOF)
{
if(!strcmp(a,"GET"))
{
if(q.empty())
printf("EMPTY QUEUE!\n");
else
{
printf("%s %d\n",q.top().name,q.top().x);
q.pop();
}
}
else if(!strcmp(a,"PUT"))
{
scanf("%s %d %d",Q.name,&Q.x,&Q.y);
Q.num=count;
count++;
q.push(Q);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: