标签:
考察优先队列,不过要注意优先队列的优先排序是不稳定排序,解决方法和自定义排序一样,再添加一个参数即可
#include<iostream>
#include<queue>
using namespace std;
string cmd;
struct stu
{
string name;
int p,lv,num;
friend bool operator<(stu x,stu y)
{
if(x.lv==y.lv) return x.num>y.num;
return x.lv>y.lv;
}
};
stu x;
priority_queue<stu>mapp;
int main()
{
int t=0;
while(cin>>cmd)
{
if(cmd=="GET")
{
if(!mapp.size()) cout<<"EMPTY QUEUE!"<<endl;
else cout<<mapp.top().name<<" "<<mapp.top().p<<endl,mapp.pop();
}
else
{
cin>>x.name>>x.p>>x.lv;
x.num=t++;
mapp.push(x);
}
}
return 0;
}hdu 1509 Windows Message Queue
标签:
原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/45199405