题目大意:n条队伍,然后开始组成一条长队,如果长队中已经有自己人,直接插队插到自己人最后面,如果没有乖乖排最后。
题目思路:使用map容器记录每个人对应的队伍,然后插入的时候判断队里有没有自己人,如果没有的话就把对应的队伍号放到长队q的最后面,输出的时候先看长队q.front()对应的那个队伍还有没有人,没人的话就让下一个队伍输出
以下是代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<queue>
using namespace std;
int main(){
int n,a,b,num=0;
string cmd;
while(~scanf("%d",&n)&&n){
printf("Scenario #%d\n",++num);
map<int,int>team;
queue<int>q,q2[1005];
for(int i=0;i<n;i++){
scanf("%d",&a);
for(int j=0;j<a;j++){
scanf("%d",&b);
team[b]=i;
}
}
while(cin>>cmd){
if(cmd[0]=='S'){
break;
}
else if(cmd[0]=='E'){
int temp,t;
scanf("%d",&temp);
t=team[temp];
if(q2[t].empty()){
q.push(t);
}
q2[t].push(temp);
}
else if(cmd[0]=='D'){
int t=q.front();
while(q2[t].empty()){
q.pop();
t=q.front();
}
printf("%d\n",q2[t].front());
q2[t].pop();
}
}
printf("\n");
}
}