题目链接:

  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容器模拟消息队列)的更多相关文章

  1. zoj 2724 Windows Message Queue

    Windows Message Queue Time Limit: 2 Seconds      Memory Limit: 65536 KB Message queue is the basic f ...

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

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

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

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

  4. zoj 2724 Windows Message Queue 优先队列

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

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

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

  6. ZOJ 2724 Windows 消息队列 (优先队列)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 Message queue is the basic fund ...

  7. hdu 1509 Windows Message Queue

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

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

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

  9. Windows Message Queue(优先队列)

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

随机推荐

  1. codeforces 477D

    题意:给定一个长度<=5000的二进制字符串S,以及一个初始为0的n,有一下两种操作: 1. 输出n(n>=1并且为2进制形式输出) 2.n=n+1 每次选择一种操作.. 求:1.有多少方 ...

  2. OpenStack Kilo版加CEPH部署手册

    OpenStack Kilo版加CEPH部署手册 作者: yz联系方式: QQ: 949587200日期: 2015-7-13版本: Kilo 转载地址: http://mp.weixin.qq.co ...

  3. 一次典型的TFS故障处理:域控失联

    问题描述 突然收到客户报告,开发人员登录TFS系统时,出现登录异常现象.即使输入了正确的账户和密码,TFS系统任然提示重新登录的页面,导致用户无法打开TFS系统. 即使登录成功,在修改代码或者修改工作 ...

  4. 查看指定spid的脚本当前运行情况和状态

    USE MasterGO declare @spid int; select @spid = 419--null:all ; ;WITH DATA(spid,blockRelationship,blo ...

  5. Python2 指定文件编码格式需要注意的地方

    python2 中默认的编码格式是unicode, 开发人员经常需要根据需要,将python文件的编码格式设置为utf-8,我们可以在python文件的第一行进行设置,加入如下代码: # encodi ...

  6. mybatis四大接口之 ParameterHandler

    1.  继承结构 只有一个默认的实现类 2. ParameterHandler 获取参数对象: 设置参数对象: public interface ParameterHandler { Object g ...

  7. maven搭建ssm初级框架

    喜欢的朋友可以关注下,粉丝也缺. 前言: 想必大家对smm框架已经熟悉的不能再熟悉了,它是由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架. ...

  8. python学习笔记13-集合set

    set  集合 把不同的元素组合在一起  可以去除相同的元素  set(可哈希的) 无序不重复的.  取值:遍历取或者迭代取值 可哈希:不可变类型 set整体是非可哈希的. 即可变集合 不可变集合:f ...

  9. 5_Python OOP

    1. 实例属性和类属性        (1) 实例属性在构造函数__init__中定义,定义时以self作为前缀,只能通过实例名访问        (2) 类属性在类中方法之外单独定义,还可以在程序中 ...

  10. WebDriver高级应用实例(8)

    8.1使用Log4j在测试过程中打印日志 目的:在测试过程中,使用Log4j打印日志,用于监控和后续调试测试脚本 被测网页的网址: http://www.baidu.com 环境准备: (1)访问ht ...