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!

按优先度,然后相同的FIFO,不能用vector然后自己排,复杂度太高会T,只能用优先队列;

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
struct pp
{
char name[20];
int num,lev,id;
friend bool operator <(pp a,pp b)
{
if(a.lev ==b.lev)
return a.id >b.id ;//要加个这个,符合FIFO,不然会错
return a.lev >b.lev;
}
};
priority_queue<pp>v;
void Get()
{
if(v.empty()) pf("EMPTY QUEUE!\n");
else{
pp t=v.top();
pf("%s %d\n",t.name,t.num);
v.pop();
}
}
int main()
{
int ans=1;
while(!v.empty()) v.pop();
char q[5];
while(~sf("%s",q))
{
if(q[0]=='G')
Get();
else
{
pp t;
sf("%s%d%d",t.name,&t.num,&t.lev);
t.id =ans++;
v.push(t);
}
}
return 0;
}

H - Windows Message Queue的更多相关文章

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

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

  2. Windows Message Queue(优先队列)

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

  3. Windows Message Queue

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

  4. hdu 1509 Windows Message Queue

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

  5. zoj 2724 Windows Message Queue

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

  6. hdu 1509 Windows Message Queue (优先队列)

    Windows Message QueueTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. D - Windows Message Queue

    来源hdu1509 Message queue is the basic fundamental of windows system. For each process, the system mai ...

  8. HDU 1509 Windows Message Queue(队列)

    题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...

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

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

随机推荐

  1. 独热编码和dummy编码的作用

    参考这篇文章: https://www.cnblogs.com/lianyingteng/p/7792693.html 总结:我们使用one-hot编码时,通常我们的模型不加bias项 或者 加上bi ...

  2. Spring ActiveMQ 整合(三): 确认机制ACK(收到消息后,应该有一个回应也就是确认答复)

    https://blog.csdn.net/dly1580854879/article/details/68490197

  3. 简单JNI使用demo

    android中使用JNI的小例子,直接上代码. 首先是Java类JniClient,定义native方法,User实体类就不上代码了,就简单定义了三个属性,name.age.sex. package ...

  4. Android.mk简介<转>

    文章参照:http://blog.sina.com.cn/s/blog_67d8d7060100q8un.html Android.mk文件是GNU Makefile的一小部分,它用来对Android ...

  5. Vue加载组件、动态加载组件的几种方式

    https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...

  6. InnoDB 存储引擎的主要知识点介绍

    本文转载自:Draveness,略有修改 原文链接:『浅入浅出』MySQL 和 InnoDB · 面向信仰编程 作为一名开发人员,在日常的工作中会难以避免地接触到数据库,无论是基于文件的 sqlite ...

  7. 12C -- ORA-65048 ORA-65048

    创建common user的时候报错: $ sqlplus '/as sysdba' SQL*Plus: Release 12.2.0.1.0 Production on Tue Apr 18 11: ...

  8. Spark 论文篇-Spark:工作组上的集群计算的框架(中英双语)

    论文内容: 待整理 参考文献: Spark: Cluster Computing with Working Sets. Matei Zaharia, Mosharaf Chowdhury, Micha ...

  9. R8500 MPv2 版本 刷 Kong编译的 ddwrt 后,使用Entware-ng 安装opkg安装第三方软件

    先说R8500吧. 由于Netgear网件的问题导致R8500在去年双11前夕出现了全球范围的Boot Loop的问题,现象为新设备开机一段时间后,路由器进入不停重启的状态,电源灯桔黄色.在和网件工程 ...

  10. [svc]sort-uniq

    uniq - report or omit repeated lines sort -r -t uniq -r -c uniq的作用: 去除相邻重复行 [root@n1 data]# cat ip.t ...