Windows Message Queue

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

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!

题解:优先队列,要考虑同一优先级时的出列顺序;由于优先队列当优先级相同时随机输出队列,所以加一个z;否则wa;

代码:

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN=;
struct Node{
char ms[];
int x,y,z;
friend bool operator < (Node a,Node b){
if(a.y!=b.y)return a.y > b.y;
else return a.z>b.z;
}
};
Node people;
int main(){int k=;
char temp[];priority_queue<Node>message;
while(memset(temp,,sizeof(temp)),scanf("%s",temp)!=EOF){
if(!strcmp(temp,"GET")){
if(message.empty())puts("EMPTY QUEUE!");
else printf("%s %d\n",message.top().ms,message.top().x),message.pop();
}
else if(!strcmp(temp,"PUT"))k++,scanf("%s %d %d",people.ms,&people.x,&people.y),people.z=k,message.push(people);
}
return ;
}

Windows Message Queue(优先队列)的更多相关文章

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

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

  2. zoj 2724 Windows Message Queue 优先队列

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...

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

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

  4. hdu 1509 Windows Message Queue

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

  5. Windows Message Queue

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

  6. zoj 2724 Windows Message Queue

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

  7. hdu1509(Windows Message Queue) 优先队列

    点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...

  8. HDU 1509 Windows Message Queue(队列)

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

  9. D - Windows Message Queue

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

随机推荐

  1. OpenReports中文支持方案

    此文章在<OpenReports中文支持完全解决方案.doc>的基础上做优化,并贴出代码.已测试通过. 一.主要解决的问题 1 页面显示支持中文 2 与服务器或数据库的交互支持中文 3 查 ...

  2. ajaxFileUpload SyntaxError: syntax error

    在使用ajaxFileUpload上传文件时,Chrome没问题,IE和Firefox出错,Firefox报SyntaxError: syntax error错误 JS代码例如以下: $.ajaxFi ...

  3. NPOI之使用EXCEL模板创建报表

    因为项目中要用到服务器端创建EXCEL模板 无法直接调用EXCEL 查了下发现NPOI很方便很简单就实现了 其中走了点弯路 第一次弄的时候发现输出的值是文本不是数字型无法直接计算公式 然后又发现打开报 ...

  4. [Hapi.js] View engines

    View engines, or template engines, allow you to maintain a clean separation between your presentatio ...

  5. C# Datatable导出Excel方法

    C# 导出Excel方法  先引用下System.IO;System.data; 具体函数如下: public static bool ExportCSV(DataTable dt, string f ...

  6. ASP.NET MVC 部分视图(转)

    [部分视图] ASP.NET MVC 里的部分视图,相当于 Web Form 里的 User Control.我们的页面往往会有许多重用的地方,可以进行封装重用.使用 部分视图 :  1. 可以简写代 ...

  7. PL/SQL文档

    http://www.oracle.com/technetwork/database/features/plsql/index.html 注册表学习 http://itlab.idcquan.com/ ...

  8. calc()函数的使用

    calc()函数算是css中的一个另类了,一般来说css都是直接确定的样式,而calc()函数却是可以动态计算,这和css静态的概念有些区别,但这并不妨碍其优秀的性能. 什么是calc()? calc ...

  9. jira汉化

    https://translations.atlassian.com/dashboard/dashboard 下载汉化jar文件,在jira中上传插件,系统设置中文即可 LOFTER:我们的故事    ...

  10. HTTP的一些基础知识

    HTTP是计算机通过网络进行通信的规则.http是一种无状态协议:不建立持久的连接,服务端不保留连接信息. 一个完整的HTTP请示,通常用7个步骤:1.建立TCP连接2.Web浏览器向Web服务器发送 ...