Windows Message Queue
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1926 accepted submission (s): 752
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 will add a message to the queue.
Meanwhile, the process will do a loop for getting message from the queue according to the priority value if it is not empty. note that the less priority value means the higher priority. in this problem, you are 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 line is a 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 two integer means the Parameter
And priority followed. there will be at most 60000 command. note that one message can be appear twice or more and if two messages have the same priority, the one comes first will be processed first. (I. E ., FIFO for the same priority .) process to the end-of-file.
Outputfor each "get" command, output the command getting from the Message Queue with the name and parameter in one line. If there's no message in the queue, output "Empty queue! ". There's no output for" put "command.
Sample Input
GETPUT msg1 10 5PUT msg2 10 4GETGETGET
Sample output
EMPTY QUEUE!msg2 10msg1 10EMPTY QUEUE!
Authorzhou, ran
// It is quite painful for WA many times. Then, a chronological order is added. Isn't it automatically sorted by chronological order based on the same priority? # Include <iostream> # include <stdio. h ># include <queue> using namespace STD; struct node {string s; int W; int t; friend bool operator <(node A, Node B) {if (. w! = B. w) return. w> B. w; else return. t> B. t ;}}; priority_queue <node> q; int main () {string something, P; int X, Y; int time = 0; while (CIN> something) {If (something = "get") {If (Q. empty () {cout <"Empty queue! "<Endl;} else {cout <q. top (). S <Endl; q. pop () ;}} else if (something = "put") {CIN >>>> x> Y; char TMP [100]; sprintf (TMP, "% d", x); something + = TMP; node N; N. S = something; N. W = y; N. t = time ++; q. push (n) ;}} return 0 ;}