HDU-1509 Windows Message Queue

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1509 Priority Queue frolicked problem. Windows Message Queue

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 4120 Accepted Submission (s): 1620

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, 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 inputgetput msg1 5PUT msg2 4getgetget sample outputempty QUEUE !MSG2 10MSG1 10EMPTY queue!
#include <iostream>#include<cstring>#include<cstdio>#include<queue>using namespacestd;structnode{friendBOOL operator<(node N1,node n2) {if(n1.priority==n2.priority)returnN1.id>n2.id; Else           returnN1.priority>n2.priority; }    intID; intPriority ; intvalue; Chars[ -];};intMain () {Chart[4]; intk=1;; intx, y; Priority_queue<node>Q; structnode p;  while(~SCANF ("%s", T)) {        if(t[0]=='P') {scanf ("%s%d%d",p.s,&p.value,&p.priority); P.id=k++;             Q.push (P); }            Else            {            if(t[0]=='G')            {                if(!Q.empty ()) {P=Q.top (); printf ("%s%d\n", P.s,p.value);                Q.pop (); }                Elsecout<<"EMPTY queue!"<<Endl; }            }     }    return 0;}

HDU-1509 Windows Message Queue

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.