您的位置:首页 > 其它

hdu 1509 优先队列

2011-11-08 22:03 344 查看
View Code

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node{
char s[20];
int canshu;
int priority;
int num;
bool operator < (const node&b) const{
if(priority==b.priority)
return num>b.num;
return priority>b.priority;
}
};
int main()
{
int i,j,t;
char str[20];
priority_queue<node>Q;
//     scanf("%d",&t);
int tot=0;
while(scanf("%s",str)!=EOF)
{
if(strcmp(str,"GET")==0)
{
if(!Q.empty())
{printf("%s %d\n",Q.top().s,Q.top().canshu); Q.pop();}
else printf("EMPTY QUEUE!\n");

}
else
{
node tmp;
scanf("%s%d%d",tmp.s,&tmp.canshu,&tmp.priority);
tmp.num=++tot;
Q.push(tmp);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: