-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeam Queue.cpp
54 lines (54 loc) · 941 Bytes
/
Team Queue.cpp
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
#include <cstdio>
#include <queue>
#include <string>
#include <map>
using namespace std;
const int maxn = 2000;
int main()
{
int n, kase = 0;
FILE* fin = fopen("data.in", "r");
while(fscanf(fin, "%d", &n) == 1 && n)
{
int mbrcnt, member;
map<int, int > team;
queue<int> q, q1[maxn];
printf("Scenario #%d\n", ++kase);
for(int i = 0; i < n; i++)
{
fscanf(fin, "%d", &mbrcnt);
for(int j = 0; j < mbrcnt; j++)
{
fscanf(fin, "%d", &member);
team[member] = i;
}
}
char cmd[10];
int seq;
while(1)
{
fscanf(fin, "%s", cmd);
if(cmd[0] == 'S')
break;
else if(cmd[0] == 'D')
{
int x = q.front();
int y = q1[x].front();
q1[x].pop();
printf("%d\n", y);
if(q1[x].empty())
q.pop();
}
else if(cmd[0] == 'E')
{
fscanf(fin, "%d", &seq);
int x = team[seq];
if(q1[x].empty())
q.push(x);
q1[x].push(seq);
}
}
printf("\n");
}
return 0;
}