-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP608.cpp
66 lines (64 loc) · 1.25 KB
/
P608.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
void add(string &s, set<char> &S) {
FORUI(s.size()) {
char c = s[i];
if(S.find(c) == S.end())
S.insert(c);
}
}
void intersect(string &s, set<char> &S) {
set<char> ss;
FORUI(s.size()) {
char c = s[i];
if(S.find(c) != S.end())
ss.insert(c);
}
S = ss;
}
int main() {
FORCAS {
set<char> heavy, light, even;
bool firstUneven = true;
FORI(3) {
GS(left); GS(right); GS(type);
if(type[0] == 'e') {
add(left, even);
add(right, even);
}
else if(type[0] == 'u') {
if(firstUneven) {
add(left, heavy);
add(right, light);
firstUneven = false;
}
else {
intersect(left, heavy);
intersect(right, light);
}
}
else {
if(firstUneven) {
add(right, heavy);
add(left, light);
firstUneven = false;
}
else {
intersect(right, heavy);
intersect(left, light);
}
}
}
for(char c = 'A'; c <= 'L'; ++c) {
bool e = even.find(c) != even.end();
bool h = heavy.find(c) != heavy.end();
bool l = light.find(c) != light.end();
if(e || (h && l) || (!e && !h && !l))
continue; // Not counterfit.
cout << c << " is the counterfeit coin and it is ";
if(h)
cout << "heavy." << endl;
else
cout << "light." << endl;
}
}
return 0;
}