书上的代码交上去Runtime Error,故按照自己的思路重写了
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t, cnt = 0;
while(scanf("%d", &t), t!=0)
{
map<int, int> team;
queue<int> qu;
map<int, queue<int>> x;
for(int i = 0; i < t; i++)
{
int m;
scanf("%d", &m);
for(int j = 0; j < m; j++)
{
int stu;
scanf("%d", &stu);
team.insert(make_pair(stu, i));
}
}
printf("Scenario #%d\n", ++cnt);
char cmd[16];
while(scanf("%s", cmd), cmd[0]!='S')
{
if(cmd[0]=='E')
{
int stu;
scanf("%d", &stu);
if(x[team[stu]].empty())
{
qu.push(team[stu]);
x[team[stu]].push(stu);
}
else
x[team[stu]].push(stu);
}
else if(cmd[0]=='D')
{
int front_team;
front_team = qu.front();
printf("%d\n", x[front_team].front());
x[front_team].pop();
if(x[front_team].empty())
qu.pop();
}
}
printf("\n");
}
return 0;
}