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 }
  • 相关阅读:
    用番茄工作法提升工作效率 (二)用番茄钟实现劳逸结合(简单到不可相信)
    Scratch少儿编程系列:(九)音乐高级技巧
    Scratch少儿编程系列:(八)演奏简单音乐
    BOM (字节顺序标记)
    获取 / 设置 进程的工作目录(当前目录)
    内存对齐
    WPF 透明窗体
    C# 调用 C++ 的 DLL 返回值为 bool 时,值混乱
    WPF ListView / ListBox 更新绑定数据源时,自动刷新界面显示
    正则表达式——WPF输入控件TextBox 限定输入特定字符
  • 原文地址:https://www.cnblogs.com/homura/p/4682776.html
Copyright © 2011-2022 走看看