Problem link can be found here
1 #include<bits/stdc++.h>
2 using
namespace std;
3 int belong_to[1000001];
4 queue<int>team_queue[1001];
5 queue<int>combined;
6 int main(){
7 //
freopen("in.txt","r",stdin);
8 //freopen("out.txt","w",stdout);
9 int tc,k,cases=0;
10 while(cin>>tc){
11 if(tc==0)return 0;
12 for(int i=0;i<tc;i++){
13 cin>>k;
14 while(!team_queue[i].empty()){
15 team_queue[i].pop();
16 }
17 while(!combined.empty()){
18 combined.pop();
19 }
20 while(k--){
21 int elem;
22 cin>>elem;
23 belong_to[elem]= i;
24 }
25 }
26 cases++;
27 printf("Scenario #%d\n",cases);
28 string command;
29 int num;
30 while(cin>>command, command[0]!= 'S'){
31 if(command[0] == 'E'){
32 cin>>num;
33 int team = belong_to[num];
34 if(team_queue[team].empty()){
35 combined.push(team);
36 }
37 team_queue[team].push(num);
38 }
39
40 else{
41 int team = combined.front();
42 cout<<team_queue[team].front()<<endl;
43
44 team_queue[team].pop();
45 if(team_queue[team].empty()){
46 combined.pop();
47 }
48
49 }
50
51 }
52 cout<<"\n";
53 }
54 return 0;}
No comments:
Post a Comment