2018学校暑期集训第一天——C++与STL

练习题D ——  HDU - 1509

D - 振电迁移的日蚀

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!

emmm……这道题和E题当时没有时间来不及写了……

问题描述
消息队列是windows系统的基本(basic fundamental)。对于每个程序,系统都会有一个消息队列。如果这个程序被操作,比如鼠标点击,文本(text)修改,系统将会给队列发送消息。与此同时,在非空的情况下,程序将会根据优先级值(priority value)从队列中不断得到消息。注意,优先级值越低表示的优先级越高。在这个问题中,你要模仿接收消息和发送消息的队列。

输入
输入项中只有一种情况。每一行是一个指令,接受或发送,即接收消息和发送消息。如果指令是发送,则会有一个表示消息名称的字符串还有两个整数,一个表示参数(parameter),一个表示优先权(priority)最多会有60000条指令。注意,一条消息能够出现两次或者更多,如果两条消息具有同样的优先权,那么先接收的那条将被执行(IE,FIFO都是这样的)。直至文件结束。

输出
对于每条接受指令,从消息队列中输出一行消息名和参数。如果在队列中没有消息,那么输出空队列。对于接受指令则没有输出。

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;struct Message {static int idFactory;string name;int id, parm, priority;static int getID() {return idFactory++;}Message(string name = "", int parm = 0, int priority = 0) {this->id = getID();this->name = name;this->parm = parm;this->priority = priority;}bool operator < (const Message &rhs) const {if (priority == rhs.priority) {return id > rhs.id;} else {return priority > rhs.priority;}}void print() const {cout << name << " " << parm << endl;}
};int Message::idFactory = 0;int main(int argc, char *argv[]) {priority_queue<Message> pq;string command, name;int parm, priority;ios::sync_with_stdio(false);while (cin >> command) {if (command == "GET") {if (pq.empty()) {cout << "EMPTY QUEUE!" << endl;} else {pq.top().print();pq.pop();}} else {cin >> name >> parm >> priority;Message newMsg(name, parm, priority);pq.push(newMsg);}}return 0;
}

暑期集训1:C++STL 练习题D:HDU-1509相关推荐

  1. 暑期集训1:C++STL 练习题C:HDU-1263

    2018学校暑期集训第一天--C++与STL 练习题C --   HDU - 1263 C - 亡失流转的孤独 夏天来了~~好开心啊,呵呵,好多好多水果~~  Joe经营着一个不大的水果店.他认为生存 ...

  2. 暑期集训1:C++STL 练习题B:HDU-1004

    2018学校暑期集训第一天--C++与STL 练习题B --  HDU - 1004 B - 双对福音的协议 Contest time again! How excited it is to see ...

  3. 暑期集训1:C++STL 练习题E:POJ-2431

    2018学校暑期集训第一天--C++与STL 练习题E --  POJ - 2431 E - 二律背反的对偶 A group of cows grabbed a truck and ventured ...

  4. 暑期集训1:C++STL 练习题A:POJ-1833

    2018学校暑期集训第一天--C++与STL 练习题A -- POJ-1833 A - 闭时曲线的引言 Time Limit: 1000MS   Memory Limit: 30000K Total ...

  5. 暑期集训1:C++STL 例1:UVA-10815

    2018学校暑期集训第一天--C++与STL 例一  --  UVA - 10815 Andy's First Dictionary Description XY学长刚刚立下了再不过CET就直播xx的 ...

  6. 暑期集训1:C++STL 例3:UVA-12100

    2018学校暑期集训第一天--C++与STL 例三  --  UVA - 12100 Printer Queue The only printer in the computer science st ...

  7. 暑期集训1:C++STL 例2:UVA-10935

    2018学校暑期集训第一天--C++与STL 例二  --  UVA - 10935 Throwing cards away I Given is an ordered deck of n cards ...

  8. 题解报告(CDUT暑期集训——第二场)

    题解报告(CDUT暑期集训--第二场) D - Game HDU - 6312 思路:水题 Alice一直是必胜态 AC代码 #include<stdio.h> #include<i ...

  9. 暑期集训5:并查集 线段树 练习题G: HDU - 1754

    2018学校暑期集训第五天--并查集 线段树 练习题G  --   HDU - 1754 I Hate It 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让 ...

最新文章

  1. mysql 存储过程基础_MySQL基础-存储过程
  2. python一:hello world
  3. 设计模式之facade模式
  4. OneAPM Cloud Test——系统性能监控神器
  5. 数据库分库分表(sharding)系列(五) 一种支持自由规划无须数据迁移和修改路由代码的Sharding扩容方案...
  6. vuejs 轮播_如何在VueJS中设计和构建轮播功能
  7. pandas打印全部列_python——pandas练习题1-5
  8. html+正则+换行+回车,正则与回车换行符使用详解
  9. 等了一年终于要来了 电影《八佰》定档8月21日全国上映
  10. 建立p2p互相连接的社区集群机器人设计(一)
  11. android版自动答录机,自动答录机app下载-自动答录机 安卓版v2.4.6.2-PC6安卓网
  12. ORACLE 10g下载地址
  13. 重心法选址迭代matlab,配送中心重心法选址的研究
  14. 会议室管理系统源码分享-Spring mvc+mybatis+jpa+mysql+bootstrap
  15. 深棕颜色html的色号,棕色rgb颜色值 有谁知道咖啡色的RGB值?
  16. picpick截屏软件脱壳
  17. Windows窗口(DirectX3D11学习笔记)
  18. 在java里四舍五入怎么做_利用java怎么实现一个四舍五入功能
  19. linux如何修改当前时间
  20. 浙江大学软件学院人工智能保研面经2021

热门文章

  1. 从外部导入django模块
  2. Cocos2d-x Eclipse下程序运行产生错误Effect initCheck() returned -1
  3. uva 10183 How many Fibs?
  4. 拿到WP官方主题Twenty Ten就是一顿nofollow伺候
  5. 计算机一级ps2019,2019年计算机一级考试PS基础学习点子:PS菜单中英文对照表.docx...
  6. SunlightChain 区块链宣言
  7. vim block vim_如何不再害怕Vim
  8. 1052 Linked List Sorting
  9. (C++)1025 PAT Ranking
  10. 花钱参加UI设计培训值得吗?