AcWing 132. 小组队列
原题链接
简单
作者:
Value
,
2020-09-03 11:12:53
,
所有人可见
,
阅读 428
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
const int N = 1010, M = 1E6;
int teamid[M];
int main(){
int n, C = 1;
while(cin >> n, n){
printf("Scenario #%d\n", C ++ );
for(int i = 0; i < n; i ++ ){
int cnt; cin >> cnt;
while(cnt -- ){
int id; cin >> id;
teamid[id] = i;
}
}
string command;
queue<int> team;
queue<int> inteam[N];
while(cin >> command, command != "STOP"){
if(command == "ENQUEUE"){
int id; cin >> id;
int tid = teamid[id];
if(inteam[tid].empty()) team.push(tid);
inteam[tid].push(id);
}else{
int tid = team.front();
cout << inteam[tid].front() << endl;
inteam[tid].pop();
if(inteam[tid].empty()) team.pop();
}
}
cout << endl;
}
return 0;
}