UVa 540 Team Queue

请参考佳佳的书

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
const int maxt = 1000 + 9;
int t = 0;
map<int, int> team;
void solve()
{
  for (int i = 0; i < t; i++)
  {
    int n;
    cin >> n;
    for (int j = 0; j < n; j++)
    {
      int x;
      cin >> x;
      team[x] = i;
    }
  }
  queue<int> q, q2[maxt];
  for (; ;)
  {
    string cmd;
    cin >> cmd;
    if (cmd[0] == 'S') break;
    if (cmd[0] == 'D')
    {
      int t = q.front();
      cout << q2[t].front() << endl;
      q2[t].pop();
      if (q2[t].empty()) q.pop();
    }else
    {
      int x;
      cin >> x;
      int t = team[x];
      if (q2[t].empty()) q.push(t);
      q2[t].push(x);
    }
  }
  cout << endl;
}
int main()
{
  //freopen("input.txt", "r", stdin);
  for (int i = 1; ;i++)
  {
    cin >> t;
    if (t == 0) break;
    cout << "Scenario #" << i << endl;
    solve();
  }
}

你可能感兴趣的:(UVa 540 Team Queue)