https://vjudge.net/problem/UVA-540
#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std;
#pragma warning(disable:4996)
const int maxn = 1005;
int main(){
#ifdef _DEBUG
freopen("in", "rb", stdin);
//freopen("out", "wb", stdout);
#endif // _DEBUG
int t, n,tt,cnt=0;
map<int, int> team;//建立人员编号到队伍编号的映射
while (cin >> t && t) {
for (int i = 1; i <= t; ++i) {//给队伍进行编号
cin >> n;
while (n--) {
cin >> tt;
team[tt] = i;
}
}
string str;
queue<int> que,qt[maxn];//que只记录队伍编号
printf("Scenario #%d\n", ++cnt);
while (cin >> str && str[0] != 'S') {
if (str[0] == 'D') {
int _team = que.front();
printf("%d\n", qt[_team].front());
qt[_team].pop();
if (qt[_team].empty()) que.pop();
}
else {
cin >> tt;
int _num = team[tt];
if (qt[_num].empty()) que.push(_num);
qt[_num].push(tt);
}
}
cout << endl;
}
}