Sample Input
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
Sample Output
2 EMPTY 3 1 1
AC代码
#include<stdio.h>
#include<queue>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct node
{
int k; //优先级
int t; //顺序
}p;
bool operator<(const node &a,const node &b)
{
if(a.k==b.k)
return a.t>b.t; //优先级相同,先来的优先
else
return a.k<b.k; //优先权高的优先
}
int main()
{
int n;
while(~scanf("%d",&n))
{
int l=1;
priority_queue<node>q[4]; //优先队列 定义的是一个队列数组
for(int i=0;i<n;i++)
{
getchar(); //吸收空格
char ch[10];
int a,b;
cin>>ch;
if(ch[0]=='I')
{
cin>>a>>b;
p.t=l++;
p.k=b;
q[a].push(p);
}
else
{
cin>>a;
if(!q[a].empty())
{
p=q[a].top();
q[a].pop();
cout<<p.t<<endl;
}
else
{
cout<<"EMPTY"<<endl;
}
}
}
}
return 0;
}