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 }
  • 相关阅读:
    SQL Server中六种数据移动的方法
    SQL Server数据导入导出技术概述与比较
    深入浅出SQL之左连接、右连接和全连接
    安装SQL server提示安装不上,挂起之类
    如何在SQL Server中快速删除重复记录
    SQL Server数据导入导出工具BCP详解
    深入浅出SQL教程之嵌套SELECT语句
    使用osql执行sql脚本
    sql server 分组统计
    php常用几种设计模式的应用场景
  • 原文地址:https://www.cnblogs.com/cssystem/p/3212495.html
Copyright © 2011-2022 走看看