zoukankan      html  css  js  c++  java
  • 杭电1509--Windows Message Queue(优先队列)

    Windows Message Queue

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4329    Accepted Submission(s): 1715


    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!
     

     

    Author
    ZHOU, Ran
     

     

    Source
     

     

    Recommend
    linle   |   We have carefully selected several similar problems for you:  1873 1512 1387 1710 1896 
    //AC :
     1 #include <queue>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 struct ac
     7 {
     8     char ch[10];
     9     int para, pri, id;
    10     friend bool operator < (ac para, ac pri)
    11     {
    12         if(para.pri == pri.pri)
    13         return para.id > pri.id;   //从小 → → 大;
    14         else
    15         return para.pri > pri.pri; //*优先级比较,数越小,优先级越大*
    16     }
    17 };
    18 
    19 int main()
    20 {
    21     ac t;
    22     int a, b, ans= 0;
    23     char ko[10], s[10];
    24     priority_queue <ac> q;
    25     //priority_queue <int, vector<int>, greater<int> > q; // 小 → → 大 ; 
    26     //priority_queue <int, vector<int>, less<int> > q;     // 大 → → 小; 
    27     while(~scanf("%s", s))
    28     {
    29         if(s[0] == 'P')
    30         {
    31             scanf("%s %d %d", ko, &a, &b);
    32             strcpy(t.ch, ko);
    33             t.para = a;
    34             t.pri = b;
    35             t.id = ++ans;
    36             q.push(t);
    37         }
    38         else
    39         {
    40             if(!q.empty())
    41             {
    42                 t = q.top();
    43                 q.pop();
    44                 printf("%s %d
    ", t.ch, t.para); 
    45             }
    46             else
    47             printf("EMPTY QUEUE!
    ");
    48         }
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    hadoop
    flume
    IP地址查询
    flinkStreamSQL
    StreamSets
    Algorightm----DynamicProgramming
    google
    vue学习
    使用Webstorm快速启动Vue项目配置
    数据库——关系代数中的除法运算【转】
  • 原文地址:https://www.cnblogs.com/soTired/p/4682386.html
Copyright © 2011-2022 走看看