题目链接:传送门
#include <iostream>
#include <cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct node
{
char name[30];
int pr,cs,cunt;
friend bool operator <(node a,node b)
{
if(a.pr!=b.pr)
return a.pr>b.pr;
return a.cunt>b.cunt;
}
};
int main()
{
node temp;
int ans=0,i;
priority_queue<node>q;
char str[20];
while(~scanf("%s",str))
{
if(!strcmp(str,"GET"))
{
if(!q.empty())
{
temp=q.top();
printf("%s %d\n",temp.name,temp.cs);
q.pop();
}
else printf("EMPTY QUEUE!\n");
}
else if(!strcmp(str,"PUT"))
{
scanf("%s %d %d",temp.name,&temp.cs,&temp.pr);//a是cs,b=pr
temp.cunt=ans++;
q.push(temp);
}
}
return 0;
}