代码如下
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
map<int,int> m1;
int main()
{
int times=1;
int qnum;
while(cin>>qnum,qnum!=0)
{
cout<<"Scenario #"<<times<<endl;
times++;
queue <int> q1;
queue<int> qteam[1000];
for(int i=1;i<=qnum;i++)
{
int t1;
cin>>t1;
for(int j=1;j<=t1;j++)
{
int t2;
cin>>t2;
m1[t2]=i;
}
}
string op;
while(cin>>op,op!="STOP")
{
if(op=="ENQUEUE")
{
int t3;
cin>>t3;
if(qteam[m1[t3]].empty())
{
cout<<m1[t3]<<" 队"<<"加入了 "<<endl;
q1.push(m1[t3]);
qteam[m1[t3]].push(t3);
}
else
{
qteam[m1[t3]].push(t3);
}
cout<<m1[t3]<<" 队"<<"加入了 "<<t3<<endl;
}
else if(op=="DEQUEUE")
{
cout<<qteam[q1.front()].front()<<endl;
qteam[q1.front()].pop();
if(qteam[q1.front()].empty())
q1.pop();
}
}
}
return 0;
}