博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdoj- Windows Message Queue
阅读量:5124 次
发布时间:2019-06-13

本文共 2223 字,大约阅读时间需要 7 分钟。

                    Windows Message Queue

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!
 

代码

#include
#include
#include
using namespace std;struct Message{ char str[100]; int l; int z; int por;friend bool operator < (Message a,Message b){ if(a.por==b.por) return a.z>b.z; else return a.por>b.por;}};int main(){ int i,j,z=1; Message message1; Message message2; char mess[100]; priority_queue
q; while(!q.empty()) q.pop(); while(~scanf("%s",mess)) { if(strcmp(mess,"PUT")==0) { message1.z=z++; scanf("%s%d%d",message1.str,&message1.l,&message1.por); q.push(message1); } if(strcmp(mess,"GET")==0) { if(q.empty()==1) printf("EMPTY QUEUE!\n"); else { message2=q.top(); q.pop(); printf("%s %d\n",message2.str,message2.l); } } } return 0;}

 

转载于:https://www.cnblogs.com/playboy307/p/5273859.html

你可能感兴趣的文章
MyBatis入门
查看>>
曾国藩:诚敬静谨恒!
查看>>
ASP.NET数据格式的Format-- DataFormatString
查看>>
IOS+Android马甲包封装上架!
查看>>
【Immutable】拷贝与JSON.parse(JSON.stringify()),深度比较相等与underscore.isEqual(),性能比较...
查看>>
WPF - 自定义标记扩展
查看>>
WLC exclusionlist
查看>>
Calculation控制台
查看>>
unity3d教程游戏包含的一切文件导入资源
查看>>
Swift的笔记和参考
查看>>
栈溢出实践
查看>>
insert---插入记录
查看>>
UML基础知识点
查看>>
ueditor使用-图片上传正常,图片显示异常404
查看>>
windows快捷键
查看>>
xampp默认mysql数据库root密码的修改
查看>>
架构实战:(一)Redis采用主从架构的原因
查看>>
安装php时,make步骤报错make: *** [sapi/fpm/php-fpm] Error 1
查看>>
安卓——launchMode
查看>>
jQuery 实现一个简单的信息反馈或者信息收集的页面
查看>>