Windows Message Queue
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4329 Accepted Submission (s): 1715
Problem Descriptionmessage queue is the basic fundamental of Windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text change, the system would add a message to the queue. Meanwhile, the process would do a loop for getting message from the queue according to the priority value if it's not empt Y. Note the less priority value means the higher priority. In this problem, you is asked to simulate the message queue for putting messages to and getting message from the message Queue.
Inputthere ' s only one test case in the input. Each command, "GET" or "PUT", which means getting message or putting message. If the command is "PUT",
there ' re one string means the message name and both integer means the parameter and priority followed by. There'll is at the most 60000 command.
Note that one message can appear twice or more and if the messages has the same priority, the one comes first would be Processed First. (i.e., FIFO for the same priority.) Process to the End-of-file.
Outputfor each "GET" command, the output of the command getting from the message queue with the name and parameter on one line. If There's no message in the queue, output "EMPTY queue!". There ' s no output for "PUT" command.
Sample Inputget put MSG1 5 put MSG2 4 get get
Sample Outputempty queue! MSG2 MSG1 EMPTY queue!
Authorzhou, Ran
Sourcezhejiang University Local Contest 2006, Preliminary
Recommendlinle | We have carefully selected several similar problems for you:1873 1512 1387 1710 1896//ac:
1#include <queue>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 structAC7 {8 Charch[Ten];9 intpara, PRI, id;TenFriendBOOL operator<(AC para, ac pri) One { A if(Para.pri = =Pri.pri) - returnPara.id > Pri.id;// - Else the returnPara.pri > Pri.pri;//* Priority Comparison * - } - }; - + intMain () - { + AC t; A intA, B, ans=0; at Charko[Ten], s[Ten]; -Priority_queue <ac>Q; - //priority_queue <int, vector<int>, greater<int> > Q;//small →→ Large; - //priority_queue <int, vector<int>, less<int> > Q; //large →→ small; - while(~SCANF ("%s", s)) - { in if(s[0] =='P') - { toscanf"%s%d%d", Ko, &a, &b); + strcpy (t.ch, KO); -T.para =A; theT.pri =b; *T.id = + +ans; $ Q.push (t);Panax Notoginseng } - Else the { + if(!q.empty ()) A { thet =q.top (); + Q.pop (); -printf"%s%d\n", t.ch, T.para); $ } $ Else -printf"EMPTY queue!\n"); - } the } - return 0;Wuyi}
Hangzhou Electric 1509--windows Message Queue (priority queue)