1. 程式人生 > >團體隊列(UVa540)

團體隊列(UVa540)

mes c++11 con iostream return front lan lin dex

  

  題目具體描述見:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=481

C++11代碼如下:

 1 #include<iostream>
 2 #include<map>
 3 #include<string>
 4 #include<queue>
 5 using namespace std;
 6 
 7 const int maxn = 1010;
 8 
 9 int main() {
10 int t, k = 0; 11 while ((cin >> t) && t ) { 12 cout << "Scenario #" << ++k << endl; 13 queue<int>q, q2[maxn]; 14 map<int, int>team; 15 16 for(int i=1;i<=t;i++) { 17 int n, m; 18 cin >> n;
19 while (n--) { 20 cin >> m; 21 team[m] = i; 22 } 23 } 24 for (;;) { 25 string cmd; int x; 26 cin >> cmd; 27 if (cmd[0] == S) break; 28 else if (cmd[0] ==
E) { 29 cin >> x; 30 int k = team[x]; 31 if (q2[k].empty()) q.push(k); 32 q2[k].push(x); 33 } 34 else if (cmd[0] == D) { 35 int d = q.front(); 36 int num = q2[d].front(); q2[d].pop(); 37 if (q2[d].empty()) q.pop(); 38 cout << num << endl; 39 } 40 } 41 cout << endl; 42 } 43 return 0; 44 }

團體隊列(UVa540)