题目链接:

  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. maven工程聚合和继承的意义

    聚合的意义: 对于一个大型的项目,如果我们直接作为一个工程开发,由于相互之间的依赖我们只能从头到尾由一组人开发,否则就会出现一个类好多人开发,相互更改的混乱局面,这个时候我们就将项目进行了横向和纵向的 ...

  2. GetFileOpenName()、GetFilesavename

    GetFileOpenName() 功能显示打开文件对话框,让用户选择要打开的文件. 语法:GetFileOpenName(title,pathname,filename{,extension{,fi ...

  3. Alpha阶段scrum meeting七天冲刺博客-天冷记得穿秋裤队

    Alpha阶段scrum meeting七天冲刺博客 day url 第一天 https://www.cnblogs.com/laomiXD/articles/9874052.html 第二天 htt ...

  4. JPA Annotation注解

    JPA & Hibernate 注解 先说说JPA和Hibernate的关系 JPA(Java Persistence API),是Java EE 5的标准ORM接口,也是ejb3规范的一部分 ...

  5. G 最水的一道

    G - Here Be Dragons The Triwizard Tournament's third task is to negotiate a corridor of many segment ...

  6. Android-okhttp下载网络图片并设置壁纸

    在AndroidManifest.xml配置网络访问权限: <!-- 访问网络是危险的行为 所以需要权限 --> <uses-permission android:name=&quo ...

  7. sqlserver,杀掉死锁的进程

    USE [erpdb1]GO/****** Object:  StoredProcedure [dbo].[p_lockinfo_MyKill]    Script Date: 12/26/2014 ...

  8. 讲讲我当年是怎么拿到AI研发公司offer的

    前言 很多的老铁私信问我,当年我是怎么拿到公司offer的,我记得我毕业是2015年,那时人工智能这个行业还没热起来,能提供的岗位很少但是面试的人更少,我又是本专业毕业的,所以当初找工作还算顺利,去面 ...

  9. Android逆向——smali复杂类解析

    i春秋作家:HAI_ 之前在Android逆向——初识smali与java类中讲解了基本的HelloWorld和简单类.这节课就要进一步深入.如果能够耐下心来分析一定会有所收获.——写给自己和后来人. ...

  10. webpack快速入门——实战技巧:watch的正确使用方法,webpack自动打包

    随着项目大了,后端与前端联调,我们不需要每一次都去打包,这样特别麻烦,我们希望的场景是,每次按保存键,webpack自动为我们打包,这个工具就是watch! 因为watch是webpack自带的插件, ...