题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=481

C++11代码如下:

 #include<iostream>
#include<map>
#include<string>
#include<queue>
using namespace std; const int maxn = ; int main() {
int t, k = ;
while ((cin >> t) && t ) {
cout << "Scenario #" << ++k << endl;
queue<int>q, q2[maxn];
map<int, int>team; for(int i=;i<=t;i++) {
int n, m;
cin >> n;
while (n--) {
cin >> m;
team[m] = i;
}
}
for (;;) {
string cmd; int x;
cin >> cmd;
if (cmd[] == 'S') break;
else if (cmd[] == 'E') {
cin >> x;
int k = team[x];
if (q2[k].empty()) q.push(k);
q2[k].push(x);
}
else if (cmd[] == 'D') {
int d = q.front();
int num = q2[d].front(); q2[d].pop();
if (q2[d].empty()) q.pop();
cout << num << endl;
}
}
cout << endl;
}
return ;
}
05-12 07:50