您的位置:首页 > 其它

zoj 2724

2013-07-30 21:52 344 查看
看了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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  优先队列 zoj