Topic Links:
http://acm.split.hdu.edu.cn/showproblem.php?pid=1509
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 InputGetput MSG1 5PUT msg2 4GETGETGET
Sample OutputEMPTY queue!msg2 10MSG1 10EMPTY queue!
Hint:
Test instructions
Priority queue.
Exercises
Priority queue, water problem.
Code:
#include <cstdio> #include <cstring> #include <queue> #include <iostream> #include < Algorithm>using namespace Std;struct node{ char name[100+10]; int x,val; int time; friend bool Operator < (node A,node b) { if (a.val!=b.val) return a.val>b.val; Return a.time>b.time; }} S;char A[10];int Main () { int num=0; priority_queue<node>q; while (!q.empty ()) q.pop (); while (scanf ("%s", a)!=eof) { if (strcmp (A, "GET") ==0) { if (Q.empty ()) printf ("Empty QUEUE !\n "); else { node b=q.top (); Q.pop (); printf ("%s%d\n", b.name,b.x); } } else { scanf ("%s%d%d", s.name,&s.x,&s.val); s.time=num++; Q.push (s);}} }
HDU 1509 Windows Message Queue