Windows Message Queue
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9202    Accepted Submission(s): 3836
Problem Description
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!

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = ; char buf[MAX];
int id = ; struct node
{
char name[MAX];
int n, val, id;
friend bool operator < (node a, node b)
{
if (a.val != b.val)
return a.val > b.val;
return a.id > b.id;
}
}; int main()
{
priority_queue <node> Q;
while (~scanf("%s", &buf))
{
if (strcmp(buf, "GET") == )
{
if (Q.empty()) printf("EMPTY QUEUE!\n");
else
{
printf("%s %d\n", Q.top().name, Q.top().n);
Q.pop();
}
}
else
{
node temp;
temp.id = id ++;
scanf("%s %d %d", &temp.name, &temp.n, &temp.val);
Q.push(temp);
}
}
}

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

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...

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

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

  5. zoj 2724 Windows Message Queue 优先队列

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

  6. Windows Message Queue(优先队列)

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

  7. Windows Message Queue

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

  8. zoj 2724 Windows Message Queue

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

  9. hdu1509(Windows Message Queue) 优先队列

    点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...

随机推荐

  1. Redis 3.0中文版学习(二)

    网址:http://wiki.jikexueyuan.com/project/redis-guide/entry-to-master-middle.html 1.Redis的列表: 采用链表的实现方法 ...

  2. 新手也能看懂的 SpringBoot 异步编程指南

    本文已经收录自 springboot-guide : https://github.com/Snailclimb/springboot-guide (Spring Boot 核心知识点整理. 基于 S ...

  3. 高通电源管理函数的power_supply的调用关系

    以msm8909为例,高通的主要文件有几个: qpnp-linear-charger.c(线性充电器) qpnp-vm-bms.c(BMS管理) power_supply_core.c(power_s ...

  4. 定制的print()输出格式

    #定制print时的显示内容 #烤地瓜案例:主要显示格式digua("cd1","cd2","cd3""),而不是就直接在一个列表 ...

  5. python3.x以上 爬虫 使用问题 urllib(不能使用urllib2)

    问题一: python 3.x 以上版本揽括了 urllib2,把urllib2 和 urllib 整合到一起. 并且引入模块变成一个,只有 import urllib # import urllib ...

  6. 用Python校准本地时间

    目录 1. 概念 1.1 基本概念 1.2 版本演进 2. 示例演示 2.1 前提条件 2.2 完整代码 2.3 其他问题 3. 参考信息: 1. 概念 1.1 基本概念 时间,对于我们来说很重要,什 ...

  7. vscode发博客插件更新v0.1.0(可能会相对好用点吧)

    距离上一次编写这个vscode在博客园发博客的插件已经过去好久了,那个时候vscode插件的功能也没有那么强大,期间有人提出问题来,也有人提出建议来,我一直没有抽出时间来维护,深感抱歉,直到有人加到我 ...

  8. Yii 1.1.x 单元测试

    代码若不整洁,只会越来越糟糕:代码写不好,公司要黄是迟早. Yii 的应用有两种,下面记录这两种应用的单元测试方法 webApplication consoleApplication 在protect ...

  9. 接口 IEnumerable

    C#提供了可供类继承的接口,在此解释一下经常遇到的IEnumerable,在此首相解释一下接口,如下例所示: /// <summary> /// 简述Interface的用法 /// &l ...

  10. Flask:数据库的操作

    1.对数据库的增加操作 在Django中,数据库查询需要借助objects方法,在Flask中也有类似的操作.在执行对数据库的增加操作之前,我们首先需要实例化一个session对象,这里的sessio ...