看病要排队Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13362 Accepted Submission(s): 5663 Problem Description 看病要排队这个是地球人都知道的常识。 Input 输入数据包含多组测试,请处理到文件结束。 Output 对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。 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 Author linle Source Recommend lcy |
#include<queue>
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
struct que
{
int id,level;
friend bool operator < ( que ca,que cb) //重载<号是从大到小排序,>号是从小到大排序
{
if(ca.level != cb.level)
return ca.level < cb.level;
else
return ca.id > cb.id;
}
}temp;
int N;
int main()
{
int i,j; //循环变量
while(~scanf("%d",&N))
{
string ch; //IN 和 OUT
int doctor,level; //医生和优先度
priority_queue<que> p[4]; //定义 优先队列
int ans=0; //排队
// que temp;
while(N--)
{
cin>>ch;
if(ch=="IN")
{
cin>>doctor>>level;
temp.id=++ans;
temp.level=level;
p[doctor].push(temp);
}
else
{
cin>>doctor;
if(p[doctor].empty())
{
printf("EMPTY\n");
}
else
{
printf("%d\n",p[doctor].top().id);
p[doctor].pop();
}
}
}
}
return 0;
}