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的更多相关文章

  1. zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...

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

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

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

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

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

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

  5. zoj 2724 Windows Message Queue 优先队列

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

  6. hdu 1509 Windows Message Queue

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

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

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

  8. Windows Message Queue(优先队列)

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

  9. Windows Message Queue

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

随机推荐

  1. 513 Find Bottom Left Tree Value 找树左下角的值

    给定一个二叉树,在树的最后一行找到最左边的值. 详见:https://leetcode.com/problems/find-bottom-left-tree-value/description/ C+ ...

  2. Java 学习列表

    这是从450家企业的招聘信息中统计而来,相对来说还是比较真实的,虽然有些公司的招聘要求万年不变,但还是可以大致反应企业的招聘要求的.

  3. props.children 和容器类组件

    有一类组件,充当了容器的作用,它定义了一种外层结构形式,然后你可以往里面塞任意的内容.这种结构在实际当中非常常见,例如这种带卡片组件: 组件本身是一个不带任何内容的方形的容器,我可以在用这个组件的时候 ...

  4. AJPFX实例集合嵌套之ArrayList嵌套ArrayList

    案例:import java.util.ArrayList;import java.util.Iterator;import com.heima.bean.Person;public class De ...

  5. AJPFX总结面向对象(this和super的区别和应用)

    面向对象(this和super的区别和应用)(掌握)* A:this和super都代表什么        * this:代表当前对象的引用,谁来调用我,我就代表谁        * super:代表当 ...

  6. LN : leetcode 416 Partition Equal Subset Sum

    lc 416 Partition Equal Subset Sum 416 Partition Equal Subset Sum Given a non-empty array containing ...

  7. UVa OJ 458

     The Decoder  Write a complete program that will correctly decode a set of characters into a valid m ...

  8. js单线程和js异步操作的几种方法

    一.为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事. JavaScript的单线程,与它的用途有关.作为浏览器脚本语言,JavaS ...

  9. 远程桌面连接windowsServer

    1.win+R 打开windows运行工具栏: 2.输入 mstsc ,确定: 3.登录设置: 计算机:目标服务器ip地址:用户名:管理员或者用户的用户名,例如:administrator:密码:账户 ...

  10. itop安装中使用nginx安装后不能出现enter itop的问题

    安装中没有出现enter itop,  如下的网络请求给了我们原因 原来使用的是域名请求资源文件,而该域名并不能指向我的服务器,所以安装中资源文件请求不成功,查看了我的nginx配置,如下 [ro ...