方法:
优先队列,控制好优先条件。
第一个是按照优先级来排列,若优先级相同,则按照先后顺序排列。
AC代码:
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
struct news
{
string name;
int par;
int yx;
int num;
bool operator < (const news &p)const
{
if(yx==p.yx)
{
return num>p.num;
}
return yx > p.yx;
}
};
int main()
{
string mes;
priority_queue<news> ss;
int k = 1;
while(cin>>mes)
{
if(mes=="PUT")
{
news s;
cin>>s.name>>s.par>>s.yx;
s.num = k++;
ss.push(s);
}
if(mes=="GET")
{
if(ss.empty())
{
cout<<"EMPTY QUEUE!"<<endl;
}
else
{
news s = ss.top();
cout<<s.name<<" "<<s.par<<endl;
ss.pop();
}
}
}
return 0;
}