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 }
  • 相关阅读:
    Maven打包时去掉项目版本号
    maven编译的时候排除junit测试类
    Redis与Zookeeper实现分布式锁的区别
    分布式锁(基于redis和zookeeper)详解
    解读阿里巴巴集团的“大中台、小前台”组织战略
    java高并发系列
    JAVA之Unsafe学习笔记
    测试用例之正交排列法
    测试用例之因果图/判定表
    测试用例之边界值法
  • 原文地址:https://www.cnblogs.com/cssystem/p/3212495.html
Copyright © 2011-2022 走看看