来源hdu1509

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<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#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;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=3e2+10;
class mes
{
public:
char name[50];
int cnt;
int num,val;
friend bool operator <(mes a,mes b)
{
if(a.val==b.val)
return a.cnt>b.cnt;
return a.val>b.val;
}
};
priority_queue<mes> v;
void print(mes a)
{
pf("%s %d\n",a.name,a.num);
}
int main()
{
int cas=1;
char a[5];
while(~sf("%s",a))
{
if(a[0]=='G')
{
if(v.empty())
pf("EMPTY QUEUE!\n");
else
{
print(v.top());
v.pop();
} }else
{
mes t;
t.cnt=cas++;
sf("%s%d%d",t.name,&t.num,&t.val);
v.push(t);
}
}
return 0;
}

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

  1. hdu 1509 Windows Message Queue

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

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

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

  3. Windows Message Queue(优先队列)

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

  4. Windows Message Queue

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

  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. HDU 1509 Windows Message Queue(队列)

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

  8. H - Windows Message Queue

    Message queue is the basic fundamental of windows system. For each process, the system maintains a m ...

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

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

随机推荐

  1. JSAP101

    JSAP101 1.DOM 1)文档对象模型 文档:把一个Html文件看成一个文档,所以把这个文档看成一个对象.XML文件也可以看成一个文件.XML侧重于存储数据,html主要以展示为主.一个页面就是 ...

  2. .Net转Java.04.踩到switch的坑

    今天线上有个NullPointerException 的异常,我翻了一下代码,抛异常的竟然是switch语句 我有种不祥的预感,本地做了实验 结果是 Java的switch如果传入null值,会抛出  ...

  3. linux下gflags的安装

    gflags是google开发的一套命令行参数解析工具,被很多软件系统所依赖,应该算是一个基础的库,安装其实很简单,但是如果在网上找的一些教程大部分都是安装后不能被其他软件调用的,因为默认使用cmak ...

  4. srs2.0安装问题

    原文: https://blog.csdn.net/ddr77/article/details/52511340 编译配置如下 ./configure --disable-all --with-ssl ...

  5. Android ListView滚动到指定的位置

    这篇文章主要给大家介绍了Android中的ListView如何滚动到指定的位置,文章给出了两种解决的方法,并给出详细的示例代码,相信会对大家的理解和学习很有帮助,有需要的朋友们下面来一起看看吧. 本文 ...

  6. JAVA中通过Jedis操作Redis连接与插入简单库

    一.简述 JAVA中通过Jedis操作Redis连接与插入简单库 二.依赖 <!-- https://mvnrepository.com/artifact/redis.clients/jedis ...

  7. Android编码学习之Fragment

    1. 什么是Fragment Fragment是Android honeycomb 3.0新增的概念,Fragment名为碎片不过却和Activity十分相似.Fragment是用来描述一些行为或一部 ...

  8. 一步步教你轻松学KNN模型算法

    一步步教你轻松学KNN模型算法( 白宁超 2018年7月24日08:52:16 ) 导读:机器学习算法中KNN属于比较简单的典型算法,既可以做聚类又可以做分类使用.本文通过一个模拟的实际案例进行讲解. ...

  9. c/c++字节序转换(转)

    字节序(byte order)关系到多字节整数(short/int16.int/int32,int64)和浮点数的各字节在内存中的存放顺序.字节序分为两种:小端字节序(little endian)和大 ...

  10. Android studio Program type already present: com.****.BuildConfig

    Android studio 抛错,是因为有2个module在 AndroidManifest.xml 里面具有一样的package name,修改不同名字即可. 还有一种情况是多个module对同一 ...