Mahmoud_Hawara

Untitled

Jul 19th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int N = 1e6 + 5;
  7. const int dx[4] = {0, 0, 1, -1};
  8. const int dy[4] = {1, -1, 0, 0};
  9.  
  10. long long t, n, x, belongTo[N], cnt;
  11.  
  12. int main()
  13. {
  14.     while (cin >> t && t)
  15.     {
  16.         cnt++;
  17.         queue<long long>team[1005];
  18.         for (int i = 1; i <= t; i++)
  19.         {
  20.             cin >> n;
  21.             while (n--)
  22.             {
  23.                 cin >> x;
  24.                 belongTo[x] = i;
  25.             }
  26.         }
  27.         cout << "Scenario #" << cnt << '\n';
  28.         queue<long long>teamNum;
  29.         string comm;
  30.         while (cin >> comm && comm[0] != 'S')
  31.         {
  32.             if (comm[0] == 'E')
  33.             {
  34.                 long long x;
  35.                 cin >> x;
  36.                 if (team[belongTo[x]].empty())
  37.                 {
  38.                     teamNum.push(belongTo[x]);
  39.                 }
  40.                 team[belongTo[x]].push(x);
  41.             }
  42.             else
  43.             {
  44.                 long long frontTeam = teamNum.front();
  45.                 cout << team[frontTeam].front() << '\n';
  46.                 team[frontTeam].pop();
  47.                 if ( team[frontTeam].empty())
  48.                 {
  49.                     teamNum.pop();
  50.                 }
  51.             }
  52.         }
  53.         cout << '\n';
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment