Windows Message Queue HDU 1509

题意:
意思就是看样例就明白了~

优先级高的先输出,优先级相同的话那么我们就按照顺序来输出

思路:这个题对我来说是比较难的了,从题中我们很容易看出要采用结构体来做,然后因为是大的先输出,我们很容易想到优先队列。这里注意优先级队列如果插入的节点是结构体类型,则要在结构体中重载比较操作符函数。

#include<bits/stdc++.h>

using namespace std;

struct node{
	char name[110];
	int num,id,no;
	friend bool operator<(node a,node b){
	  if(a.no != b.no) return a.no > b.no;
	  return a.id > b.id;}
};
priority_queue <node> q;


int main(){
	char a[110];
	int i = 0;
	while(cin>>a){
		node temp;
		if(strcmp(a,"GET")==0){//如果是GET
			if(!q.empty()){
				cout<<q.top().name<<" "<<q.top().num<<endl;
			    q.pop();
			}
			else{
				cout<<"EMPTY QUEUE!"<<endl;
			}
		}
		else{
			cin>>temp.name>>temp.num>>temp.no;
			temp.id = ++i;//表示先后顺序
			q.push(temp);
		}
	}
	return 0;
}