#include<bits/stdc++.h>
using namespace std;
int main()
{
map<int,int>ans;
queue<int>q; //队列1,每个成员的队伍编号
queue<int>q2[2000]; //队列2,每个团队成员构成一个队列
int n,m,x;
string s;
int coun=0;
while(cin>>n)
{ if(n==0) break;
cout<<"Scenario #"<<++coun<<endl;
for(int i=0;i<n;i++)
{
cin>>m;
while(m--)
{
cin>>x;
ans[x]=i; //给每个队伍成员映射一个队伍编号 (map)
}
}
while(cin>>s)
{
if(s[0]=='S') break;
else if(s[0]=='E')
{
cin>>x;
int t=ans[x];
if(q2[t].empty()) q.push(t); //如果编号为t的队伍没有人,就在队列添加一个编号t的队伍
q2[t].push(x); //在编号t的队伍里添加一个成员
}
else
{
int t=q.front();
cout<<q2[t].front()<<endl;q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
for(int i=0;i<n;i++) //每次STOP后的数据都要清空!!!!
while(q2[i].empty()==0) q2[i].pop(); // 因为初学不熟练,这三行的清空导致wa了3次。。
while(q.empty()==0) q.pop(); // 看了网上代码才想起来还要这个
cout<<endl;
}
return 0;
}
UVA540
最新推荐文章于 2023-10-05 12:47:33 发布