hdu 1509 优先队列

View Code
 1 #include<stdio.h>
2 #include<string.h>
3 #include<queue>
4 using namespace std;
5 struct node{
6 char s[20];
7 int canshu;
8 int priority;
9 int num;
10 bool operator < (const node&b) const{
11 if(priority==b.priority)
12 return num>b.num;
13 return priority>b.priority;
14 }
15 };
16 int main()
17 {
18 int i,j,t;
19 char str[20];
20 priority_queue<node>Q;
21 // scanf("%d",&t);
22 int tot=0;
23 while(scanf("%s",str)!=EOF)
24 {
25 if(strcmp(str,"GET")==0)
26 {
27 if(!Q.empty())
28 {printf("%s %d\n",Q.top().s,Q.top().canshu); Q.pop();}
29 else printf("EMPTY QUEUE!\n");
30
31 }
32 else
33 {
34 node tmp;
35 scanf("%s%d%d",tmp.s,&tmp.canshu,&tmp.priority);
36 tmp.num=++tot;
37 Q.push(tmp);
38 }
39 }
40 return 0;
41 }

 

 

posted @ 2011-11-08 22:03  Because Of You  Views(291)  Comments(0Edit  收藏  举报