Shirlies
宁静专注认真的程序媛~

直接暴力,虽然效率很差。。。。。。

View Code
 1 #include <iostream>
 2 #include <queue>
 3 using namespace std;
 4 
 5 struct node
 6 {
 7     char name[100];
 8     int para;
 9     int prio;
10     int id;
11     friend bool operator < (const node& a,const node& b)
12     {
13         if(a.prio == b.prio)
14             return a.id > b.id;
15 
16         return a.prio > b.prio;
17     }
18 };
19 
20 int main()
21 {
22     priority_queue<node> q;
23     char str[5];
24     int id = 1;
25     while(cin >> str)
26     {
27         if(str[0] == 'G')
28         {
29             if(q.empty())
30             {
31                 cout << "EMPTY QUEUE!" << endl;
32             }
33             else
34             {
35                 cout << q.top().name <<" " << q.top().para << endl;
36                 q.pop();
37             }
38         }
39         else
40         {
41             node a;
42             cin >> a.name >> a.para >> a.prio;
43             a.id = id ++;
44             q.push(a);
45         }
46     }
47 
48     return 0;
49 }
posted on 2012-09-22 21:03  Shirlies  阅读(192)  评论(0编辑  收藏  举报