博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电1509--Windows Message Queue(优先队列)
阅读量:7106 次
发布时间:2019-06-28

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

Windows Message Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4329    Accepted Submission(s): 1715

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!
 

 

Author
ZHOU, Ran
 

 

Source
 

 

Recommend
linle   |   We have carefully selected several similar problems for you:            
//AC :
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 struct ac 7 { 8 char ch[10]; 9 int para, pri, id;10 friend bool operator < (ac para, ac pri)11 {12 if(para.pri == pri.pri)13 return para.id > pri.id; //从小 → → 大;14 else15 return para.pri > pri.pri; //*优先级比较,数越小,优先级越大*16 }17 };18 19 int main()20 {21 ac t;22 int a, b, ans= 0;23 char ko[10], s[10];24 priority_queue
q;25 //priority_queue
, greater
> q; // 小 → → 大 ; 26 //priority_queue
, less
> q; // 大 → → 小; 27 while(~scanf("%s", s))28 {29 if(s[0] == 'P')30 {31 scanf("%s %d %d", ko, &a, &b);32 strcpy(t.ch, ko);33 t.para = a;34 t.pri = b;35 t.id = ++ans;36 q.push(t);37 }38 else39 {40 if(!q.empty())41 {42 t = q.top();43 q.pop();44 printf("%s %d\n", t.ch, t.para); 45 }46 else47 printf("EMPTY QUEUE!\n");48 }49 }50 return 0;51 }

 

转载于:https://www.cnblogs.com/soTired/p/4682386.html

你可能感兴趣的文章
湖南省委短信平台改造方案
查看>>
我对51CTO的心得
查看>>
mysql基本操作-表结构的调整与索引
查看>>
我的友情链接
查看>>
你是否需要安全运营中心?
查看>>
mrjob报语法错误
查看>>
解决PXE批量网络安装Linux系统时kickstart自动识别硬盘名称的问题的方案
查看>>
JVM调优实战
查看>>
前端资源(4)
查看>>
开启多台GuestOS提示无loop设备可用
查看>>
PHP编写一些检查项函数
查看>>
笨鸟先飞学编程系列之二 基础代码的编写2(转)
查看>>
samza快速理解
查看>>
spark streaming容错机制
查看>>
空间和数据库存储的区别是什么
查看>>
我的友情链接
查看>>
新站不带www域名显露出来当天快照
查看>>
[图灵程序设计丛书].高效算法:竞赛、应试与提高必修128例.pdf
查看>>
二叉树的实现及其可视化
查看>>
Android流行样式书签
查看>>