UVA-540 团体队列 题解答案代码 算法竞赛入门经典第二版
作者:互联网
GitHub - jzplp/aoapc-UVA-Answer: 算法竞赛入门经典 例题和习题答案 刘汝佳 第二版
AC代码
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include<string>
using namespace std;
int main() {
int t, n = 0, a, b, i, j;
string s;
while(cin >> t && t != 0) {
cout << "Scenario #" << ++n << endl;
map<int, int> mp;
vector<queue<int>> v(t);
queue<int> q;
for(i = 0; i < t; ++i) {
cin >> a;
for(j = 0; j < a; ++j) {
cin >> b;
mp[b] = i;
}
}
while(cin >> s && s != "STOP") {
if(s == "ENQUEUE") {
cin >> a;
if(v[mp[a]].empty()) {
q.push(mp[a]);
v[mp[a]].push(a);
} else {
v[mp[a]].push(a);
}
}
if(s == "DEQUEUE") {
cout << v[q.front()].front() << endl;
v[q.front()].pop();
if(v[q.front()].empty()) {
q.pop();
}
}
}
cout << endl;
}
return 0;
}
标签:cout,int,题解,cin,540,mp,push,UVA,include 来源: https://blog.csdn.net/qq278672818/article/details/122768571