zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
题目链接:
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
GET
PUT msg1 10 5
PUT msg2 10 4
GET
GET
GET
Sample Output
EMPTY QUEUE!
msg2 10
msg1 10
EMPTY QUEUE!
/*问题 模拟消息队列,对于每一条PUT命令,将其后的命令及参数按照优先级插入队列
对于每一条GET命令,输出位于队首的消息的名称和参数,如果队列时空的输出EMPTY QUEUE!
插入的时候注意按优先级,如果优先级相同,按照先后次序入队即可。
解题思路 使用C++STL中的优先队列。识别操作,GET输出队首或者EMPTY QUEUE!,PUT进入优先队列,定义结构体比较规则*/
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std; struct info{
char name[];
int para;
int rank;
bool operator < (const info &a) const{
return a.rank < rank;//等于的时候返回0
}
}; int main()
{
char op[];
priority_queue<info> pq;
info temp;
while(scanf("%s",op) != EOF){
if(strcmp(op,"GET") == )
{
if(pq.empty())//空
{
printf("EMPTY QUEUE!\n");
}
else//非空
{
printf("%s %d\n",pq.top().name,pq.top().para);
pq.pop();
}
}
if(strcmp(op,"PUT") == )
{
scanf("%s %d %d",temp.name,&temp.para,&temp.rank);
pq.push(temp);
}
}
}
zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)的更多相关文章
- zoj 2724 Windows Message Queue
Windows Message Queue Time Limit: 2 Seconds Memory Limit: 65536 KB Message queue is the basic f ...
- ACM解题之(ZOJ 2724)Windows Message Queue
题目来源: 点击打开链接 题目翻译: 消息队列是windows系统的基本基础.对于每个进程,系统都维护一个消息队列.如果这个过程发生某些事情,例如鼠标点击,文本改变,系统会向队列添加一条消息.同时,如 ...
- ZOJ 2724 Windows Message Queue (二叉堆,优先队列)
思路:用优先队列 priority_queue,简单 两种方式改变队列 的优先级 (默认的是从大到小) #include<iostream> #include<queue> # ...
- zoj 2724 Windows Message Queue 优先队列
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...
- ZOJ 2724 Windows Message Queue (优先级队列,水题,自己动手写了个最小堆)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- ZOJ 2724 Windows 消息队列 (优先队列)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 Message queue is the basic fund ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- hdoj 1509 Windows Message Queue【优先队列】
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- Windows Message Queue(优先队列)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Mem ...
随机推荐
- Ajax登录用户名密码
<script src="http://code.jquery.com/jquery-latest.js"></script>#引入jQuery#当点击函数 ...
- 深入探讨 Java 类加载器(转)
原帖地址:https://www.ibm.com/developerworks/cn/java/j-lo-classloader/ 类加载器是 Java 语言的一个创新,也是 Java 语言流行的重要 ...
- E - Evaluate Matrix Sum
Description Given a matrix, the elements of which are all integer number from 0 to 50, you are requi ...
- Android-okhttp
在AndroidManifest.xml配置网络访问权限: <!-- 访问网络是危险的行为 所以需要权限 --> <uses-permission android:name=&quo ...
- ScintillaNET的应用
出于工作需要,需要制作一个嵌入在桌面应用中的C语言编辑器,经过一系列调研,目前ScintillaNET应该是最合适的了,开源.轻便.功能丰富,但是踩得坑也很多,接下面一一说道. 目前Scintilla ...
- PowerDesigner的Name和Code不同步设置
1.“Tools”->"GeneralOptions"(最下方) 2.“Dialog”(左侧列表选第2个) 3.“Name to Code mirroring”的勾去掉
- C语言Socket-单工通信(客户端向服务器发送数据)
服务端(server) #include <stdio.h> #include <winsock2.h> #pragma comment(lib,"ws2_32.li ...
- 用代码来细说Csrf漏洞危害以及防御
开头: 废话不多说,直接进主题. 0x01 CSRF介绍:CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click Attack”或者Session ...
- 对于opencv全面貌的认识和理解
1.opencv其实最开始只有源码,也就是sources中的代码,sources中有个modules,进入里面是各个我们平常使用的模块,如下图. 进入任意一个模块,比如calib3d,其中有inclu ...
- [原创]K8 MSF Bind Shell TCP 连接工具
工具: K8_MSFBindShellClient_20170524[K.8]编译: 自己查壳组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8.blog.1 ...