d-windows Message QueueTime
limit:2000MS
Memory Limit:65536KB
64bit IO Format:%lld &%llu Submit Status Practice ZOJ 2724
Description
Message 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.
Input
There ' 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.
Output
For 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!
#include <stdio.h> #include <string.h> #include <string> #include <map> #include <queue># Include <algorithm>using namespace std;struct node{Char ss[30]; int pp; int DD; priority int ff;}; priority_queue< node >q; Map<int, Int>ma;bool operator< (const node &x, const node &y)//dingyi Bijiao suanzi{if (x.dd!= y.dd) {return x.dd > y.dd; } return x.ff > Y.ff;} int main () {char s[10]; while (scanf ("%s", s)!=eof) {if (s[0]== ' G ') {if (Q.empty ()) printf ("Empty QUEUE !\n "); else {node outp; OUTP = Q.top (); Q.pop (); printf ("%s%d\n", OUTP.SS, outp.pp); }} else {node newn; scanf ("%s%d%d", NEWN.SS, &newn.pp, &NEWN.DD); Newn.ff = ma[newn.dd]++; Q.push (newn); }} return 0;}
Windows Message Queue