Windows Message Queue (优先队列的应用)

来源:互联网 发布:编程证书 编辑:程序博客网 时间:2024/05/18 08:32

Windows Message Queue

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


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
GETPUT msg1 10 5PUT msg2 10 4GETGETGET
 

Sample Output
EMPTY QUEUE!msg2 10msg1 10EMPTY QUEUE!
 

Author
ZHOU, Ran
 

Source
Zhejiang University Local Contest 2006, Preliminary


这也是一道优先队列的题;
PUT string  a   b   按b的优先级入队,b小优先级越高 b一样按先后顺序来
GET   输入对头并出队


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
string g="GET";
struct node{
friend bool operator < (node n1, node n2)
{
   if(n1.a!=n2.a)
        {
            return  n1.a>n2.a;//按最后那个数,越小越优先 
        }
return n1.k>n2.k;//按进入的顺序,也是 
}
string s;
int v;
int a;
int k;
};
string b;
string c;
int main()
{
priority_queue<node >q;
int k=1;
while(cin>>c)
{


if(c==g)
{
if(q.empty())
{
cout<<"EMPTY QUEUE!"<<endl;
}
else
{
cout<<q.top().s<<" "<<q.top().v<<endl;
q.pop();
}
}
else
{
node e;
cin>>e.s>>e.v>>e.a;
e.k=k;
q.push(e);
k++;
}
}
}

人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想。


 
阅读全文
1 0
原创粉丝点击