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;
}

hdoj- Windows Message Queue的更多相关文章

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

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

  2. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  3. Windows Message Queue(优先队列)

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

  4. Windows Message Queue

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

  5. zoj 2724 Windows Message Queue

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

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

    Windows Message QueueTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. HDU 1509 Windows Message Queue(队列)

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

  8. D - Windows Message Queue

    来源hdu1509 Message queue is the basic fundamental of windows system. For each process, the system mai ...

  9. H - Windows Message Queue

    Message queue is the basic fundamental of windows system. For each process, the system maintains a m ...

  10. zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...

随机推荐

  1. MYSQL 使用自定义表变量

    mysql  用户自定义表变量,ENGINE=MyISAM DEFAULT CHARSET=gb2312; 制定编码方式,防止乱码 DROP TABLE IF EXISTS p_temp; creat ...

  2. JavaScript学习书签

    JavaScript常用正则表达式 闭包 JavaScipt DOM 变量提升

  3. tomcat 编码设置

    在Tomcat8.0之前的版本,如果你要向服务器提交中文是需要转码的(如果你没有修改server.xml中的默认编码),因为8.0之前Tomcat的默认编码为ISO8859-1. POST方式提交 r ...

  4. 如何让 HTML 识别 string 里的 '\n' 并成功换行

    只要在结果所在的 div 的 css 设置: white-space: pre-line; 然后页面就能成功识别 '\n' 并整齐的显示结果了.

  5. android studio 创建第一个app之hello world

    android studio 创建第一个app之hello world 想要用studio创建一个简单的app,结果遇到各种问题,application就是允许不起来,后来在专业人的帮助下,删除了一些 ...

  6. 【vue】挂载点概念

    ## vue vue是mvvm模型,自底向上逐层应用,用于构建用户界面的渐进式框架. ### 挂载点.模板.实例 挂载点,vue仅处理挂点下面的内容(dom节点).挂载点内部的为模板. <div ...

  7. Python学习【第5篇】:Python之函数(自定义函数,内置函数,装饰器,迭代器,生成器、模块)

    一.为什么要使用函数? 1.避免代码重用 2.提高代码的可读性 二.函数的定义与调用 1. def  函数名(参数1,参数2): ''' 函数注释''' print('函数体') return 返回值 ...

  8. 洛谷——P1572 计算分数

    P1572 计算分数 模拟+字符串 注意有两位数的情况以及负数情况 #include<bits/stdc++.h> using namespace std; string s; ],b[] ...

  9. 蓝桥-区间K大数查询

    问题描述: 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. 第二行包含n个正整数,表示给定的序列. 第三个包含一个正整数m,表示询问个 ...

  10. Spring 注解注入的几种方式(转)

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...