博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-1509 Windows Message Queue
阅读量:5065 次
发布时间:2019-06-12

本文共 2690 字,大约阅读时间需要 8 分钟。

             http://acm.hdu.edu.cn/showproblem.php?pid=1509

                     优先队列躶题。             

                   Windows Message Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4120    Accepted Submission(s): 1620

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!
#include
#include
#include
#include
using namespace std;struct node{ friend bool operator<(node n1,node n2) { if(n1.priority==n2.priority) return n1.id>n2.id; else return n1.priority>n2.priority;//小的优先级高。 } int id; int priority; int value; char s[50];};int main(){ char t[4]; int k=1;; int x,y; priority_queue
q; struct node p; while(~scanf("%s",t)) { if(t[0]=='P') { scanf("%s%d%d",p.s,&p.value,&p.priority); p.id=k++; q.push(p); } else { if(t[0]=='G') { if(!q.empty()) { p=q.top(); printf("%s %d\n",p.s,p.value); q.pop(); } else cout<<"EMPTY QUEUE!"<

 

转载于:https://www.cnblogs.com/cancangood/p/4426375.html

你可能感兴趣的文章
桌面图标修复||桌面图标不正常
查看>>
JavaScript基础(四)关于对象及JSON
查看>>
JAVA面试常见问题之Redis篇
查看>>
jdk1.8 api 下载
查看>>
getElement的几中属性介绍
查看>>
HTML列表,表格与媒体元素
查看>>
雨林木风 GHOST_XP SP3 快速装机版YN12.08
查看>>
java对象的深浅克隆
查看>>
数据结构3——浅谈zkw线段树
查看>>
Introduction to my galaxy engine 2: Depth of field
查看>>
Python 3.X 练习集100题 05
查看>>
设计器 和后台代码的转换 快捷键
查看>>
Monkey测试结果分析
查看>>
STL——配接器、常用算法使用
查看>>
STL容器之vector
查看>>
无法向会话状态服务器发出会话状态请求
查看>>
数据中心虚拟化技术
查看>>
01入门
查看>>
复习文件操作
查看>>
SQL Server 使用作业设置定时任务之一(转载)
查看>>