UVA 540-Team Queue
题目大意:编号分组然后排队,ENQUEUE x — 将x编号插入队列末,如果有同组成员在队列中则插在同组成员后面
• DEQUEUE — 队首出列,并输出
• STOP — 结束样例
解题思路:设队列数组,插队时查看队列数组中是否有成员。
#include <iostream>
#include <queue>
#include <string.h>
#include <stdio.h>
#include <map>
using namespace std;
int main() {
char com[20];
int n;
int t = 0;
while(cin >> n && n != 0) {
t++;
int m, x;
queue<int> que[1010];
queue<int> nq;
map<int, int> num;
for(int i = 0; i < n; i++) {
cin >> m;
while(m--) {
cin >> x;
num[x] = i;
}
getchar();
}
cout << "Scenario #" << t << endl;
while(scanf("%s", com)) {
int x;
if(com[0] == 'S') {
cout << endl;
break;
}
if(com[0] == 'E') {
cin >> x;
getchar();
int y = num[x];
if(que[y].empty()) {
que[y].push(x);
nq.push(y);
}
else
que[y].push(x);
}
else if(com[0] == 'D') {
if(!nq.empty()) {
int y = nq.front();
int pr = que[y].front();
cout << pr << endl;
que[y].pop();
if(que[y].empty())
nq.pop();
}
}
}
}
return 0;
}