zoukankan      html  css  js  c++  java
  • HDU 1509 Windows Message Queue

                Windows Message Queue



     

    Problem 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 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.
     

     

    Input
    There'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 by. There will be at most 60000 command. Note that one message can 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.
     

     

    Output
    For 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
    GET
    PUT msg1 10 5
    PUT msg2 10 4
    GET
    GET
    GET
     

     

    Sample Output
    EMPTY QUEUE!
    msg2 10
    msg1 10
    EMPTY QUEUE!
     
    FIFO for the same priority.
     
     1 #include<cstdio>
     2 #include<queue> 
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 struct Node
     8 {
     9     char name[10];
    10     int parameter;
    11     int priority;
    12     int order;
    13     bool operator<(const Node &a)const
    14     { 
    15         if(priority==a.priority)
    16         return order>a.order;
    17         return priority>a.priority;
    18     }
    19 };
    20 
    21 int main()
    22 {
    23     //freopen("in.txt","r",stdin);
    24     int order;
    25     char command[5];
    26     priority_queue<Node>q;
    27     order=0;
    28     while(scanf("%s",command)!=EOF)
    29     {
    30         if(strcmp(command,"GET")==0)
    31         {
    32             if(!q.empty())
    33             {
    34                 Node temp=q.top();
    35                 q.pop();
    36                 printf("%s %d
    ",temp.name,temp.parameter); 
    37             }
    38             else
    39             printf("EMPTY QUEUE!
    ");
    40         }
    41         else
    42         {
    43             Node temp;
    44             scanf("%s%d%d",temp.name,&temp.parameter,&temp.priority);
    45             temp.order=++order;
    46             q.push(temp);
    47         }
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    HDU 3401 Trade
    POJ 1151 Atlantis
    HDU 3415 Max Sum of MaxKsubsequence
    HDU 4234 Moving Points
    HDU 4258 Covered Walkway
    HDU 4391 Paint The Wall
    HDU 1199 Color the Ball
    HDU 4374 One hundred layer
    HDU 3507 Print Article
    GCC特性之__init修饰解析 kasalyn的专栏 博客频道 CSDN.NET
  • 原文地址:https://www.cnblogs.com/homura/p/4682776.html
Copyright © 2011-2022 走看看