Windows Message Queue

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<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct Message
{
char str[100];
int l;
int z;
int por;
friend bool operator < (Message a,Message b)
{
if(a.por==b.por)
return a.z>b.z;
else return a.por>b.por;
}
};
int main()
{
int i,j,z=1;
Message message1;
Message message2;
char mess[100];
priority_queue<Message>q;
while(!q.empty()) q.pop();
while(~scanf("%s",mess))
{ if(strcmp(mess,"PUT")==0)
{
message1.z=z++;
scanf("%s%d%d",message1.str,&message1.l,&message1.por);
q.push(message1);
} if(strcmp(mess,"GET")==0)
{
if(q.empty()==1)
printf("EMPTY QUEUE!\n");
else
{
message2=q.top();
q.pop();
printf("%s %d\n",message2.str,message2.l);
}
}
}
return 0;
}

最新文章

  1. 实现php连接memcached
  2. uva 129 krypton factors ——yhx
  3. 【转】Delphi+Halcon实战一:两行代码识别QR二维码
  4. props
  5. ASP.NET MVC 4源码分析之如何定位控制器
  6. (传输层)TCP协议
  7. c# winform 点菜宝接口demo程序
  8. tlplayer for ios V1.1.2加密测试版本(修复1.1.1版本 for ios7播放闪退问题)
  9. 包装类、Object类——Java笔记(八)
  10. Oracle批量操作数据库
  11. postgresql 使用pg_restore时显示role &quot;root&quot; does not exist的解决办法
  12. (其他)window10上好用的软件
  13. Oracle EBS compile PLD PLL files.
  14. Syntax error, parameterized types are only available if source level is 1.5 解决方案
  15. Java 之 Web前端(四)
  16. 从Excel表导入数据到Table
  17. 微信即将支持App直接打开小程序
  18. vue学习六之vuex
  19. hdu 5671 Matrix 标记。。。有点晕
  20. jquery formValidator 表单验证插件, ajax无法传值到后台问题的解决

热门文章

  1. JS——scroll
  2. 【译】x86程序员手册09-第3章程序指令集
  3. Requests库 更新中
  4. B+树知识点
  5. cv的期刊和会议
  6. 第八节:pandas字符串
  7. yum http源
  8. How do I drop a MongoDB database, from the command line?
  9. [Usaco2010 Mar]gather 奶牛大集会
  10. 洛谷 P1481 魔族密码