forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1013(AC).cpp
73 lines (66 loc) · 1.43 KB
/
POJ1013(AC).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
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int myabs(int a)
{
return (a > 0 ? a : -a);
}
int main()
{
int istrue[12];
int suspect[12];
char left[3][10], right[3][10], res[3][10];
int n, ni;
int i, j, mi, msum;
while(true){
if(scanf("%d", &n) != 1){
break;
}
for(ni = 0; ni < n; ++ni){
memset(istrue, 0, 12 * sizeof(int));
memset(suspect, 0, 12 * sizeof(int));
for(i = 0; i < 3; ++i){
scanf("%s%s%s", left[i], right[i], res[i]);
}
for(i = 0; i < 3; ++i){
if(strcmp(res[i], "even") == 0){
for(j = 0; left[i][j]; ++j){
istrue[left[i][j] - 'A'] = 1;
istrue[right[i][j] - 'A'] = 1;
}
}else if(strcmp(res[i], "up") == 0){
for(j = 0; left[i][j]; ++j){
++suspect[left[i][j] - 'A'];
--suspect[right[i][j] - 'A'];
}
}else if(strcmp(res[i], "down") == 0){
for(j = 0; j < left[i][j]; ++j){
--suspect[left[i][j] - 'A'];
++suspect[right[i][j] - 'A'];
}
}else{
//impossible
}
}
mi = -1;
msum = -1;
for(i = 0; i < 12; ++i){
if(istrue[i]){
continue;
}
if(msum <= myabs(suspect[i])){
mi = i;
msum = myabs(suspect[i]);
}
}
if(suspect[mi] < 0){
printf("%c is the counterfeit coin and it is light.\n", mi + 'A');
}else{
printf("%c is the counterfeit coin and it is heavy.\n", mi + 'A');
}
}
}
return 0;
}