hdu 1873看病要排队(优先队列)

# include <stdio.h>
# include <algorithm>
# include <queue>
using namespace std;
struct node
{
	int  y;
	int val;
	int num;
	friend bool operator<(node n1,node n2)
	{
		if(n1.val==n2.val)
			return n1.num>n2.num;//从小到大
		return n1.val<n2.val;//从大到小
	}
};
struct node temp;
int main()
{
	int n,i,a,b;
	int t;
	char s[5];
	priority_queue<node> A,B,C;
	while(~scanf("%d",&n))
	{
		t=0;
		while(!A.empty())
			A.pop();
		while(!B.empty())
			B.pop();
		while(!C.empty())
			C.pop();
		for(i=0;i<n;i++)
		{
			scanf("%s",s);
			if(strcmp(s,"IN")==0)
			{
				scanf("%d%d",&a,&b);
				if(a==1)
				{
					temp.val=b;
					temp.num=++t;
					A.push(temp);//A医生
				}
				else if(a==2)
				{
					temp.val=b;
					temp.num=++t;
					B.push(temp);//B医生
				}
				else
				{
					temp.val=b;
					temp.num=++t;
					C.push(temp);//C医生				
				}
			}
			else
			{
				scanf("%d",&a);
				if(a==1)
				{
					if(A.empty())
					{
						printf("EMPTY\n");
					    continue;
					}
					temp=A.top();
					A.pop();
					printf("%d\n",temp.num);
					
				}
				else if(a==2)
				{
					if(B.empty())
					{
						printf("EMPTY\n");
					   continue;
					}
					temp=B.top();
					B.pop();
						printf("%d\n",temp.num);
						}
				else
				{
					if(C.empty())
					{
						printf("EMPTY\n");
					    continue;
					}
					temp=C.top();
					C.pop();
					printf("%d\n",temp.num);
					
				}
			}
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值