看了priority_queue的用法,才做这道题,很简单.
#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct mesg{
string str;
int para;
int prio;
mesg(int a = 0):
prio(a) {}
};
bool operator<(mesg a, mesg b){
return a.prio > b.prio;
}
using namespace std;
int main()
{
priority_queue<mesg> q;
string s;
while(cin>>s){
if( s == "GET" ){
if(q.empty())
cout<<"EMPTY QUEUE!"<<endl;
else{
cout<<q.top().str<<" "<<q.top().para<<endl;
q.pop();
}
}
else{
mesg m;
cin>>m.str>>m.para>>m.prio;
q.push(m);
}
}
return 0;
}