欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励)

Windows Message Queue

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

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!

题解:优先队列,要考虑同一优先级时的出列顺序;由于优先队列当优先级相同时随机输出队列,所以加一个z;否则wa;

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<queue>
 4 using namespace std;
 5 const int MAXN=60010;
 6 struct Node{
 7     char ms[20];
 8     int x,y,z;
 9     friend bool operator < (Node a,Node b){
10         if(a.y!=b.y)return a.y > b.y;
11     else return a.z>b.z;
12 }
13 };
14 Node people;
15 int main(){int k=0;
16     char temp[5];priority_queue<Node>message;
17     while(memset(temp,0,sizeof(temp)),scanf("%s",temp)!=EOF){
18         if(!strcmp(temp,"GET")){
19             if(message.empty())puts("EMPTY QUEUE!");
20             else printf("%s %d\n",message.top().ms,message.top().x),message.pop();
21         }
22         else if(!strcmp(temp,"PUT"))k++,scanf("%s %d %d",people.ms,&people.x,&people.y),people.z=k,message.push(people);
23     }
24     return 0;
25 }

转载于:https://www.cnblogs.com/handsomecui/p/4683559.html

Windows Message Queue(优先队列)相关推荐

  1. HDOJ 1509 Windows Message Queue

    Windows Message Queue Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Othe ...

  2. 【ZOJ - 2724】【HDU - 1509】Windows Message Queue(优先队列)

    题干: Message queue is the basic fundamental of windows system. For each process, the system maintains ...

  3. D - Windows Message Queue

    来源hdu1509 Message queue is the basic fundamental of windows system. For each process, the system mai ...

  4. ZOJ2724_Windows Message Queue(STL/优先队列)

    解题报告 题意: 看输入输出就非常明确. 思路: 优先队列. #include <algorithm> #include <iostream> #include <cst ...

  5. MSMQ(Microsoft Message Queue)介绍

    利用 MSMQ(Microsoft Message Queue),应用程序开发人员可以通过发送和接收消息方便地与应用程序进行快速可靠的通信.消息处理为您提供了有保障的消息传递和执行许多业务处理的可靠的 ...

  6. Microsoft Message Queue(MSMQ:微软消息队列)简介

    一.前言 最近在安装公司的一个产品时,接触到了MSMQ,在此对MSMQ做一个简单的介绍,以便各位能对它有一个快速.直观的认识.本文针对于Microsoft Message Queue,以下提到的消息队 ...

  7. Message、Handler、Message Queue、Looper之间的关系

    2019独角兽企业重金招聘Python工程师标准>>> 在单线程模型下,为了解决线程通信问题,Android设计了一个通信机制.Message Queue(消息队列), 线程间的通信 ...

  8. 远程调用服务(RPC)和消息(Message Queue)对比及其适用/不适用场合

    在阿里的平台技术部参与开发了Dubbo(远程调用服务)和Napoli(消息解决方案),又给网站应用支持这2个产品很长一段时间,了解了这2个产品的实现及应用对这两个产品的用法. 大部分情况下," ...

  9. Message Queue中的推与拉(转)

    Message Queue的设计和实现(7) http://mp.weixin.qq.com/s/zQdDBAHu1UgJJzxH2eCHgQ 数据发送中的推与拉. 当MQ要把数据给消费者的时候,就涉 ...

最新文章

  1. POJ 2828-Buy Tickets(线段树上二分)
  2. 开发常见错误解决(3)VS2005调试程序出错,绑定句柄无效 Terminal Services
  3. 【转】理解SQL Server的安全对象和权限
  4. 数据库系统实训——实验三——子查询与组合查询
  5. HTML5 文档头部
  6. 突破大文件上传 和内网ip的端口转发
  7. 小程序开发小结-线下服务器域名部署等
  8. IOCAutofac与ORMEntityFramwork的联系--单例模式
  9. Python调用科大讯飞语音合成离线SDK
  10. 蓝桥杯c语言基础试题答案,蓝桥杯试题C语言答案.doc
  11. ajaxSubmit异步提交
  12. Linux系统面试常问问题,最常见的Linux面试题集锦
  13. javaweb网上商城系统
  14. 共享远程计算机文件夹,怎么远程访问共享文件夹
  15. 计算机夏令营英语面试,保研经验 | 夏令营面试那些事儿(内含视频)
  16. Roboastere 地盘功率限制(大方向)(RM论坛同步更新,同ID,头像)
  17. 怎样更改计算机应用图标,win7如何更改软件图标_win7修改应用程序图标的教程
  18. 家用汽车维修5:换正时带和水泵
  19. App Extension
  20. 吴裕雄--天生自然 诗经:声声慢·寻寻觅觅

热门文章

  1. 《伊拉图斯死之主》:硬核游戏也有相对放松的游戏体验
  2. 游戏中的AI及实用算法逻辑
  3. c#实现手机号码归属地查询
  4. 2022跨年代码(HTML·资源都是网上的可以直接使用)
  5. OCM备考 一、Server config 之管理表空间
  6. Kafka MirrorMaker 跨集群同步工具
  7. eclipse集成processing、PApplet、proclipsing 问题
  8. 5.16-在线词识别程序学习(ASR+IAT)
  9. 5.20打卡 equals()方法与“==”的区别
  10. LeetCode 404. 左叶子之和(Sum of Left Leaves)