标签:
3 5 2 xhd 0 zl 1 2 8600 1 ll 2 1 Ignatius 3 GETOUT 1 JOIN 1 2 GETOUT 1 GETON 3 hoho 2 GETOUT 3
xhd zl hohoHintHuge input, scanf is recommended.
#include<cstdio> #include<cstring> #include<queue> #define max 10000+100 using namespace std; struct train { char name[22]; int rp; friend bool operator < (train a,train b) { if(a.rp==b.rp) { return strcmp(a.name,b.name)<0; } return a.rp>b.rp;//从小到大排列 队伍 } }; train temp; int main() { int n,m,p;//n辆车,m条命令 int i,j; int num,num1,num2; char str[10]; while(~scanf("%d%d",&n,&m)) { priority_queue<train>q[max]; for(i=1;i<=n;++i) { scanf("%d",&p); while(p--) { scanf("%s %d",temp.name,&temp.rp); q[i].push(temp); } } while(m--) { scanf("%s",str); if(strcmp(str,"GETOUT")==0) { scanf("%d",&num); temp=q[num].top(); if(!q[num].empty())//出队列之前一定要判断非空 { printf("%s\n",temp.name); q[num].pop(); } } else if(strcmp(str,"GETON")==0) { scanf("%d",&num); scanf("%s %d",temp.name,&temp.rp); q[num].push(temp); } else if(strcmp(str,"JOIN")==0) { scanf("%d%d",&num1,&num2); while(!q[num2].empty()) { temp=q[num2].top(); q[num2].pop(); q[num1].push(temp); } } } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/yuzhiwei1995/article/details/47109993