答案如下:
#include<bits/stdc++.h>
using namespace std;
const int maxt=1010;
int main()
{
int kase=0,tn=0;
while(scanf("%d",&tn)==1&&tn)
{
cout<<"Scenario #"<<++kase<<endl;
map<int,int>fteam;
for(int i=0;i<tn;i++)
{
int t=0,p=0;
cin>>t;
while(t--)
{
cin>>p;
fteam[p]=i;
}
}
queue<int>q,q2[maxt];
for(;;)
{
char cmd[10];
cin>>cmd;
if(cmd[0]=='S')
break;
else if(cmd[0]=='E')
{
int per;
cin>>per;
int tempt=fteam[per];
if(q2[tempt].empty()) q.push(tempt);
q2[tempt].push(per);
}
else if(cmd[0]=='D')
{
int tempt=q.front();
cout<<q2[tempt].front()<<endl;
q2[tempt].pop();
if(q2[tempt].empty())
q.pop();
}
}
cout<<endl;
}
return 0;
}