Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long t, n, x, belongTo[N], cnt;
- int main()
- {
- while (cin >> t && t)
- {
- cnt++;
- queue<long long>team[1005];
- for (int i = 1; i <= t; i++)
- {
- cin >> n;
- while (n--)
- {
- cin >> x;
- belongTo[x] = i;
- }
- }
- cout << "Scenario #" << cnt << '\n';
- queue<long long>teamNum;
- string comm;
- while (cin >> comm && comm[0] != 'S')
- {
- if (comm[0] == 'E')
- {
- long long x;
- cin >> x;
- if (team[belongTo[x]].empty())
- {
- teamNum.push(belongTo[x]);
- }
- team[belongTo[x]].push(x);
- }
- else
- {
- long long frontTeam = teamNum.front();
- cout << team[frontTeam].front() << '\n';
- team[frontTeam].pop();
- if ( team[frontTeam].empty())
- {
- teamNum.pop();
- }
- }
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment