"Sort, first in first out" Windows Message Queue

Source: Internet
Author: User

Windows Message Queue time limit:1 Sec Memory limit:64 MB submit:73 solved:41 [Submit][status][disc USS] 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!
HINT

zoj2724

Source

[Submit] [Status] [Discuss]

HOME Back

is to define the array a "60002" to complete the same priority, first-in, first-out, but not the simplest, need to be improved

#include <stdio.h>structpail{Charstr[ -]; intC,q;} s[60066];intMain () {Chara[4]; intk=0, i,temp,t,x[60009]={0},c;  while(SCANF ("%s", a)! =EOF) {        if(a[0]=='G') {C=0;  for(i=0; i<=k;i++)                if(x[i]==1) {Temp=i; T=s[i].q; C=1; }            if(c==0) printf ("EMPTY queue!\n"); Else            {             for(i=0; i<=k;i++)            {                if(t>s[i].q&&x[i]==1) {T=s[i].q; Temp=i; }} printf ("%s%d\n", s[temp].str,s[temp].c); x[temp]=0; }        }        if(a[0]=='P') {scanf ("%s%d%d", s[k].str,&s[k].c,&s[k].q); x[k]=1; K++; }    }    return 0;}

"Sort, first in first out" Windows Message Queue

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.