标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4329 Accepted Submission(s): 1715
1 #include <queue> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 struct ac 7 { 8 char ch[10]; 9 int para, pri, id; 10 friend bool operator < (ac para, ac pri) 11 { 12 if(para.pri == pri.pri) 13 return para.id > pri.id; // 14 else 15 return para.pri > pri.pri; //*优先级比较* 16 } 17 }; 18 19 int main() 20 { 21 ac t; 22 int a, b, ans= 0; 23 char ko[10], s[10]; 24 priority_queue <ac> q; 25 //priority_queue <int, vector<int>, greater<int> > q; // 小 → → 大 ; 26 //priority_queue <int, vector<int>, less<int> > q; // 大 → → 小; 27 while(~scanf("%s", s)) 28 { 29 if(s[0] == ‘P‘) 30 { 31 scanf("%s %d %d", ko, &a, &b); 32 strcpy(t.ch, ko); 33 t.para = a; 34 t.pri = b; 35 t.id = ++ans; 36 q.push(t); 37 } 38 else 39 { 40 if(!q.empty()) 41 { 42 t = q.top(); 43 q.pop(); 44 printf("%s %d\n", t.ch, t.para); 45 } 46 else 47 printf("EMPTY QUEUE!\n"); 48 } 49 } 50 return 0; 51 }
杭电1509--Windows Message Queue(优先队列)
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4682386.html