#include <iostream>
#include<map>
#include <queue>
#include <string>
using namespace std;
const int maxn=1050;
int main()
{
int n,kase=0;
while(cin>>n&&n)
{
kase++;
cout<<"Scenario #"<<kase<<endl;
map<int ,int> team;
queue<int> p1, p2[maxn];//p1是整体的队列,表示有无一个队入队,p2[maxn]表示每个团队的队列
for(int i=0;i<n;i++)
{
int t;
cin>>t;
for(int j=0;j<t;j++)
{
int temp;
cin>>temp;
team[temp]=i;
}
}
string a;
while(cin>>a&&a!="STOP")
{
if(a=="ENQUEUE")
{
int num;
cin>>num;
int te=team[num];
// cout<<team[num]<<endl;
if(p2[te].empty())
p1.push(te);
p2[te].push(num);
}
else if(a=="DEQUEUE")
{
cout<<p2[p1.front()].front()<<endl;
p2[p1.front()].pop();
if(p2[p1.front()].empty())
p1.pop();
}
}
cout<<endl;
}
}
转载于:https://www.cnblogs.com/kele1997/p/6822546.html