Zoj 2724 Windows Message Queue (using Priority_queue container to impersonate Message Queuing)

Source: Internet
Author: User
Tags strcmp

Topic Links:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724

Title 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!
1 /*problem Impersonation Message Queuing, for each put command, inserts subsequent commands and parameters into the queue by priority2 for each get command, output the name and parameters of the message at the top of the queue, if the output of the queuing space is empty queue!3 when inserting the attention by priority, if the priority is the same, in order to queue in sequence. 4 solving ideas using the priority queue in C++stl. Recognition operation, get output team first or empty queue!,put into priority queue, define structure comparison rule*/5#include <cstdio>6#include <queue>7#include <cstring>8 using namespacestd;9 Ten structinfo{ One     Charname[ -]; A     intpara; -     intrank; -     BOOL operator< (ConstInfo &a)Const{ the             returnA.rank < rank;//returns 0 when equals. -     } - }; -  + intMain () - { +     Charop[5]; APriority_queue<info>PQ; at Info temp; -      while(SCANF ("%s", op)! =EOF) { -         if(strcmp (OP,"GET") ==0) -         { -             if(Pq.empty ())//Empty -             { inprintf"EMPTY queue!\n");  -             }  to             Else//Non-empty +             { -printf"%s%d\n", Pq.top (). Name,pq.top (). para); the Pq.pop ();  *             }  $         }Panax Notoginseng         if(strcmp (OP,"PUT") ==0) -         { thescanf"%s%d%d",temp.name,&temp.para,&Temp.rank); + Pq.push (temp); A         } the     }     +}

Zoj 2724 Windows Message Queue (using Priority_queue container to impersonate Message Queuing)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.