-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeverages_UVA11060.cpp
84 lines (69 loc) · 1.77 KB
/
beverages_UVA11060.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("beverages_UVA11060.in");
ofstream fout("beverages_UVA11060.out");
int main()
{
int C = 0;
while (true)
{
++C;
int n = 0;
fin >> n;
if (n == 0) break;
fout << "Case #" << C << ": Dilbert should drink beverages in this order:";
map<string, int> _map;
map<string, bool> check;
vector<string> names(n);
vector<vector<bool>> a(n, vector<bool>(n, false));
vector<int> _count(n, 0);
for (int i = 0; i <= n - 1; ++i)
{
fin >> names[i];
_map[names[i]] = i;
}
int m; fin >> m;
for (int c = 1; c <= m; ++c)
{
string u, v; fin >> u >> v;
string _key = u + " " + v;
if (check[_key] == false)
{
check[_key] = true;
a[_map[u]][_map[v]] = true;
++_count[_map[v]];
}
}
for (int c = 1; c <= n; ++c)
{
int s = 0;
while (s <= n - 1 && _count[s] != 0)
{
++s;
}
if (s == n) break;
fout << ' ' << names[s];
_count[s] = -1;
for (int j = 0; j <= n - 1; ++j)
{
if (a[s][j] == true)
{
--_count[j];
a[s][j] = false;
}
}
}
fout << ".\n\n";
}
return 0;
}