1. 程式人生 > >7-20 Windows消息隊列 (25 分)(模擬水題)

7-20 Windows消息隊列 (25 分)(模擬水題)

font aaaaaa include sele str net aaaaa reat iostream

題意:

技術分享圖片技術分享圖片?

思路: 用優先隊列直接模擬就OK了,另外優先隊列存pair的時候比較的是first的值,實測!!

技術分享圖片技術分享圖片?

上代碼:

技術分享圖片
 1 #include <iostream>
 2 #include <queue>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <cstring>
 7 #include <queue>
 8 #include <vector>
 9 #define INF 0x3f3f3f3f
10
#define FRE() freopen("in.txt","r",stdin) 11 12 using namespace std; 13 typedef long long ll; 14 typedef pair<int,string> P; 15 const int maxn = 1e5+10; 16 priority_queue<P, vector<P>, greater<P> > que; 17 string op,name; 18 int n,id; 19 20 int main() { 21 //FRE(); 22 cin>>n;
23 for(int i = 0; i<n; i++) { 24 cin>>op; 25 if(op[0]==P) { 26 cin>>name>>id; 27 que.push(P(id, name)); 28 } else { 29 if(que.empty()){ 30 cout<<"EMPTY QUEUE!"<<endl; 31 } 32 else
{ 33 P p = que.top(); 34 que.pop(); 35 cout<<p.second<<endl; 36 } 37 } 38 } 39 return 0; 40 } 41 /* 42 樣例輸入: 43 9 44 PUT msg1 5 45 PUT msg2 4 46 GET 47 PUT msg3 2 48 PUT msg4 4 49 GET 50 GET 51 GET 52 GET 53 樣例輸出: 54 msg2 55 msg3 56 msg4 57 msg1 58 EMPTY QUEUE! 59 */
View Code

7-20 Windows消息隊列 (25 分)(模擬水題)