HDU-1509 Windows Message Queue
题目链接:HDU-1509
题目大意:现在有一个消息队列 PUT向队列投放队列 GET取出队列顶数据 注意数据有优先级
解题思路:直接用优先队列就好 注意优先队列排序不稳定就好了
代码块:
#include<iostream>
#include<string>
#include<queue>
using namespace std;
typedef struct myNode{
string name;
int dataInt;
int num1;
int num2;
bool operator < (const myNode &o1) const{
if(num1 == o1.num1) return num2 > o1.num2;
else return num1 > o1.num1;
}
} node;
priority_queue<node> p;
int main(){
string strA;
int index = 0;
while(cin>>strA){
// 输出阵列
if(strA == "GET"){
if(!p.size()){
cout<<"EMPTY QUEUE!"<<endl;
}else{
node n1 = p.top();
p.pop();
cout<<n1.name<<" "<<n1.dataInt<<endl;
}
}
// 输入阵列
if(strA == "PUT"){
node n1;
cin>>n1.name>>n1.dataInt>>n1.num1;
n1.num2 = index++;
p.push(n1);
}
}
return 0;
}