#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int main() {
// freopen("input.txt","r",stdin);
int cmt;
int cas=1;
while(scanf("%d",&cmt)!=EOF,cmt) {
printf("Scenario #%d\n",cas++);
map<int,int> m;
for(int i=1;i<=cmt;i++) {
int n;
scanf("%d",&n);
int tmp;
for(int j=1;j<=n;j++) {
scanf("%d",&tmp);
m[tmp]=i;
}
}
queue<int> q,q2[1005];
char cmd[10];
while(scanf("%s",cmd)!=EOF) {
if(cmd[0]=='S') break;
else if(cmd[0]=='E') {
int x;
scanf("%d",&x);
int t=m[x];
if(q2[t].empty()) q.push(t);
q2[t].push(x);
}
else {
int t=q.front();
printf("%d\n",q2[t].front());q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
printf("\n");
}
return 0;
}
uva 540 117 页
最新推荐文章于 2023-03-27 21:05:57 发布