Windows Message QueueTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 4557 Accepted Submission (s): 1819
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 Follo Wed 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 pro Cessed 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 Input
Getput MSG1 5PUT msg2 4GETGETGET
Sample Output
EMPTY queue!msg2 10MSG1 10EMPTY queue!*/* Main idea: SMS has different priority, parameters, and MSG, read text messages according to priority reading, the same priority, according to the input sequence read */#include <stdio.h> #include <queue> #include < String.h> #include <algorithm>using namespace std;struct qu{int key;//input order int yxj;//precedence int num;//parameter char name[ 100];//text message in the character friend bool operator < (qu A,qu b)//priority queue, sorted by (previous test instructions) {if (A.yxj ==b.yxj) return A.key>b.key;re Turn a.yxj>b.yxj;}}; int main () {int I,j,k=0;char s[100];qu lw;priority_queue<qu>q;while (scanf ("%s", s)!=eof) {if (s[0]== ' G ') {if ( Q.empty ()) printf ("Empty queue!\n"), else {lw=q.top ();p rintf ("%s%d\n", Lw.name, Lw.num); Q.pop ();}} ELSE{SCANF ("%s%d%d", LW.NAME,&LW.NUM,&LW.YXJ); Lw.key =k++;q.push (LW);}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj 1509 Windows Message Queue