题目链接:

  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724

题目描述:

  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

  1. GET
  2. PUT msg1 10 5
  3. PUT msg2 10 4
  4. GET
  5. GET
  6. GET

Sample Output

  1. EMPTY QUEUE!
  2. msg2 10
  3. msg1 10
  4. EMPTY QUEUE!
  1. /*问题 模拟消息队列,对于每一条PUT命令,将其后的命令及参数按照优先级插入队列
  2. 对于每一条GET命令,输出位于队首的消息的名称和参数,如果队列时空的输出EMPTY QUEUE!
  3. 插入的时候注意按优先级,如果优先级相同,按照先后次序入队即可。
  4. 解题思路 使用C++STL中的优先队列。识别操作,GET输出队首或者EMPTY QUEUE!,PUT进入优先队列,定义结构体比较规则*/
  5. #include <cstdio>
  6. #include <queue>
  7. #include <cstring>
  8. using namespace std;
  9.  
  10. struct info{
  11. char name[];
  12. int para;
  13. int rank;
  14. bool operator < (const info &a) const{
  15. return a.rank < rank;//等于的时候返回0
  16. }
  17. };
  18.  
  19. int main()
  20. {
  21. char op[];
  22. priority_queue<info> pq;
  23. info temp;
  24. while(scanf("%s",op) != EOF){
  25. if(strcmp(op,"GET") == )
  26. {
  27. if(pq.empty())//空
  28. {
  29. printf("EMPTY QUEUE!\n");
  30. }
  31. else//非空
  32. {
  33. printf("%s %d\n",pq.top().name,pq.top().para);
  34. pq.pop();
  35. }
  36. }
  37. if(strcmp(op,"PUT") == )
  38. {
  39. scanf("%s %d %d",temp.name,&temp.para,&temp.rank);
  40. pq.push(temp);
  41. }
  42. }
  43. }

zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)的更多相关文章

  1. zoj 2724 Windows Message Queue

    Windows Message Queue Time Limit: 2 Seconds      Memory Limit: 65536 KB Message queue is the basic f ...

  2. ACM解题之(ZOJ 2724)Windows Message Queue

    题目来源: 点击打开链接 题目翻译: 消息队列是windows系统的基本基础.对于每个进程,系统都维护一个消息队列.如果这个过程发生某些事情,例如鼠标点击,文本改变,系统会向队列添加一条消息.同时,如 ...

  3. ZOJ 2724 Windows Message Queue (二叉堆,优先队列)

    思路:用优先队列 priority_queue,简单 两种方式改变队列 的优先级 (默认的是从大到小) #include<iostream> #include<queue> # ...

  4. zoj 2724 Windows Message Queue 优先队列

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...

  5. ZOJ 2724 Windows Message Queue (优先级队列,水题,自己动手写了个最小堆)

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

  6. ZOJ 2724 Windows 消息队列 (优先队列)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 Message queue is the basic fund ...

  7. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  8. hdoj 1509 Windows Message Queue【优先队列】

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  9. Windows Message Queue(优先队列)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. jdbc的配置(更新中)

    MySQL的 JDBC URL 格式 for  Connector/J 如下例: 格式如下: jdbc:mysql://[host][,failoverhost...][:port]/[databas ...

  2. hdu 1.2.7

    #include<cstdio> #include<iostream> using namespace std; int main() { //freopen("in ...

  3. MVC图片验证

    1.创建一个验证类,里面有生成验证码的两个方法. namespace YTJWGL_Common { public class ValidatorCodeTools { #region 生成校验码图片 ...

  4. WPF的xaml中特殊字符表示

    直接看表,描述很清晰 字符 转义字符 备注 & (ampersand) & 这个没什么特别的,几乎所有的地方都需要使用转义字符 > (greater-than character ...

  5. ovs flow 命令集

    流表可以有多个执行动作,是从左向右以此执行,常用动作如下: output:port: 输出数据包到指定的端口.port 是指端口的 OpenFlow 端口编号 group:group_id 输出数据包 ...

  6. OpenvSwitch端口镜像

    OVS上实现端口镜像的基本流程如下: 创建 mirror ,在 mirror 中指定镜像数据源及镜像目的地 将创建的 mirror 应用到 bridge 中 镜像数据源可以通过下面几个选项来指定: s ...

  7. AJPFX技术分析入门

    AJPFX:技术分析入门 技术分析就是指通过考察历史数据来预测未来价格走向.外汇市场是非常讲技术分析的,而且分析师的基本功就是技术分析,但是,没有对基本面的准确把握,技术分析就会含糊.但是技术分析究其 ...

  8. form表单组件

    1.sweetalert 组件地址 form组件 form表单完成的事情,:   提供input可以提交数据, 对提交的数据进行校验,提供错误提示 定义form组件 from django impor ...

  9. JavaScript Boolean( new Boolean(false) ) 其实是true

    Boolean类型是JavaScript原始数据类型(primitive type)之一:常用来表示 真或假,是或否:这个类型只有两个值:保留字true和false 一般用于控制语句:如下 if(Bo ...

  10. String.format(String format,Object... args)的用法

    String.format(String format, Object... args)方法详解 以前也看到过很多次这个用法,一直记不牢靠,今天整理一下.   我仅仅举几个例子稍做说明: String ...