标签:
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
2 EMPTY 3 1 1
<span style="font-size:14px;">#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<queue> #include<algorithm> using namespace std; char opr[10]; struct node { int level;//级别 int id;//医生编号 friend bool operator < (node a,node b)//重载 最大优先队列 { if(a.level==b.level) return a.id>b.id; else return a.level<b.level; } }; int main() { int N; node hos; while(~scanf("%d",&N)) { int count=0; priority_queue<node>q[4]; while(N--) { int doctor,level; scanf("%s",opr); if(strcmp(opr,"IN")==0) { scanf("%d%d",&doctor,&level); hos.level=level; hos.id=++count;//注意题目中的要求 q[doctor].push(hos); } else if(strcmp(opr,"OUT")==0) { scanf("%d",&doctor); if(!q[doctor].empty()) { node result=q[doctor].top(); q[doctor].pop(); printf("%d\n",result.id); } else printf("EMPTY\n"); } } } return 0; } </span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lh__huahuan/article/details/47042225