zoj 2724 Windows Message Queue
Windows Message Queue
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
using namespace std;
struct Message{
char str[];
int parameter;
int priority;
};
struct mycmp{
bool operator () (const Message &a, const Message &b){
return a.priority > b.priority;
}
};
priority_queue<Message, vector<Message>, mycmp> pq;
int main(){
char s[];
Message message;
while(scanf("%s", s) != EOF){
if(strcmp(s, "GET") == ){
if(pq.empty()){
printf("EMPTY QUEUE!\n");
continue;
} else {
printf("%s %d\n", pq.top().str, pq.top().parameter);
pq.pop();
}
} else if (strcmp(s, "PUT") == ){
scanf("%s %d %d", message.str, &message.parameter, &message.priority);
pq.push(message);
}
}
return ;
}
zoj 2724 Windows Message Queue的更多相关文章
- zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...
- ACM解题之(ZOJ 2724)Windows Message Queue
题目来源: 点击打开链接 题目翻译: 消息队列是windows系统的基本基础.对于每个进程,系统都维护一个消息队列.如果这个过程发生某些事情,例如鼠标点击,文本改变,系统会向队列添加一条消息.同时,如 ...
- ZOJ 2724 Windows Message Queue (优先级队列,水题,自己动手写了个最小堆)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- 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会输入名 ...
- 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 ...
- Windows Message Queue
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- Oracle历史版本及oracle相关软件下载地址
网站:https://edelivery.oracle.com/ 可能需要注册个账号!!!(账号注册登录自己折腾下就好了) 下载数据库或者oracle的相关软件的话,如下 选择对应的下载即可!
- 用NPOI从Excel到DataTable
NPOI功能强大,不用装Excel,就可以操作表格中数据----Excel.Sheet------>DataTable private IWorkbook workbook = null; pr ...
- nginx配置参考
server { listen 443 ssl; server_name apps.qimeng.fm; #charset koi8-r; #证书 ssl_certificate /usr/local ...
- What is Scalability?
Scalability is a system's ability to process more workload, with a proportional increase in system r ...
- [转] Figuring out why my SVCHOST.EXE is at 100% CPU without complicated tools in Windows 7
(转自:Figuring out why my SVCHOST.EXE is at 100% CPU without complicated tools in Windows 7 - Scott Ha ...
- ML-学习提纲1
http://www.sohu.com/a/130379077_468714 本文用一系列「思维导图」由浅入深的总结了「统计学」领域的基础知识,是对之前系列文章做的一次完整的梳理,也是我至今为止所有与 ...
- SQLite-And和OR运算符
SQLite - AND 和 OR 运算符 SQLite AND . OR运算符用于编译多个条件缩小在一个SQLite声明中选定的数据.这两个操作符被称为连接的操作符. 这些操作符与不同操作提供了一种 ...
- hdu5792 World is Exploding(多校第五场)树状数组求逆序对 离散化
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5792 题目描述:给你n个值,每个值用A[i]表示,然后问你能否找到多少组(a,b,c,d)四个编号,四 ...
- app支付宝授权登录获取用户信息
由后台进行地址的拼接(前台进行授权) // 生成授权的参数 String sign = ""; Long userId1 = SecurityUser.getUserId(); S ...
- web.config中配置数据库连接的两种方式
在ASP.NET中有两种配置数据库连接代码的方式,它们分别是 appSettings 和 connectionStrings .在使用 appSettings 和 connectionStrings ...