-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamQueue.cpp
More file actions
60 lines (54 loc) · 1.68 KB
/
TeamQueue.cpp
File metadata and controls
60 lines (54 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <queue>
#include <map>
using namespace std;
int main(){
int t,size, item,group, scenario = 0,element;
string cmd;
std::map<int,int> mapItemGroup;
map<int,queue<int>> qByGroup;
queue<queue<int>*> qq;
while (true)
{
cin >> t;
if(!t)
return 0;
cout << "Scenario #" << ++scenario << endl;
//Mapeia os itens por grupo
for(int group = 0; group < t; ++group){
cin >> size;
for (int j = 0; j < size; ++j){
cin >> element;
mapItemGroup[element] = group;
}
}
while (true)
{
cin >> cmd;
if (cmd == "STOP"){
cout << endl;
break;
}
else if(cmd == "ENQUEUE"){
cin >> item;
group = mapItemGroup[item]; //Pega o grupo do item
qByGroup[group].push(item); //Adciona o item na fila do grupo
if(qByGroup[group].size() == 1)
qq.push(&qByGroup[group]); //Adciona a fila do grupo na fila de filas, por referência
}
else{
//Pega o primeiro elemento da primeira fila
cout << qq.front()->front() << endl;
qq.front()->pop();//Remove o individuo
if(qq.front()->empty())
qq.pop();//Se essa fila já foi toda, remove ela da fila de fila
}
}
//Limpa essa bagunça
while(!qq.empty()){
while(!qq.front()->empty())
qq.front()->pop();
qq.pop();
}
}
}