zoukankan      html  css  js  c++  java
  • 8.1.6 Windows Message Queue

    Windows Message Queue

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

    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!

    优先队列

     1 #include <cmath>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <string>
     6 #include <cstdlib>
     7 #include <queue>
     8 using namespace std;
     9 
    10 const int maxn=210;
    11 struct qq
    12 {
    13     char s[101];
    14     int t,v,p;
    15     friend bool operator < (qq a,qq b)
    16     {
    17         if (a.p==b.p)
    18             return a.t>b.t;
    19         return a.p>b.p;
    20     }
    21 } ya;
    22 priority_queue<qq> q;
    23 char s[maxn],s1[maxn];
    24 int cnt,l;
    25 
    26 void close()
    27 {
    28 exit(0);
    29 }
    30 
    31 
    32 void init()
    33 {
    34     cnt=0;
    35     while (scanf("%s",s)!=EOF)
    36     {
    37         if (s[0]=='G')
    38         {
    39             if (q.empty())
    40                 printf("EMPTY QUEUE!
    ");
    41             else
    42             {
    43                 ya=q.top();
    44                 q.pop();
    45                 l=strlen(ya.s);
    46                 for (int i=0;i<l;i++)
    47                     printf("%c",ya.s[i]);
    48                 printf(" %d
    ",ya.v);
    49             }
    50         }
    51         else
    52         {
    53             cnt++;
    54             scanf("%s %d %d",s1,&ya.v,&ya.p);
    55             strcpy(ya.s,s1);
    56             ya.t=cnt;
    57             q.push(ya);
    58         }
    59     }
    60 }
    61 
    62 int main ()
    63 {
    64     init();
    65     close();
    66     return 0;
    67 }
  • 相关阅读:
    P1064 金明的预算方案
    P1062 数列
    P2258 子矩阵
    P1095 守望者的逃离
    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
    P1203 [USACO1.1]坏掉的项链Broken Necklace
    P1478 陶陶摘苹果(升级版)
    P2485 [SDOI2011]计算器
    逆元模板
    CloudStack 物理网络架构
  • 原文地址:https://www.cnblogs.com/cssystem/p/3212495.html
Copyright © 2011-2022 走看看