-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path1013(Search)
119 lines (108 loc) · 2.87 KB
/
1013(Search)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.Scanner;
public class Main {
public static int UP = 1;
public static int EVEN = 0;
public static int DOWN = -1;
public static int LIGHT = -1;
public static int HEAVY = 1;
public class weight{
int[] left;
int[] right;
int rel;
public weight(int[] left, int[] right, String s){
this.left = left;
this.right = right;
if(s.equals("up")) rel = UP;
else if(s.equals("down")) rel = DOWN;
else rel = EVEN;
}
}
public static void main(String args[]) throws Exception
{
//Main1013 m = new Main1013();
Scanner cin=new Scanner(System.in);
int num = cin.nextInt();
for(int iii = 0; iii < num; iii++){
weight[] weights = new weight[3];
//int len = 0;
for(int ii = 0; ii < 3; ii++) {
String leftStr = cin.next(), rightStr = cin.next(), relStr = cin.next();
int len = leftStr.length();
int[] left = new int[len], right = new int[len];
for(int i = 0; i < len; i++){
left[i] = leftStr.charAt(i) - 'A';
right[i] = rightStr.charAt(i) - 'A';
}
weights[ii] = new Main().new weight(left, right, relStr);
}
boolean[] state = new boolean[12];//true表示未排除为假币的可能
//for(boolean b: state) b = true;//开始,都有可能为假币
for(int i = 0; i < 12; i++) state[i] = true;
//for(boolean b: state) System.out.print(b + " ");
for(weight w: weights){
if(w.rel == EVEN){
for(int i: w.left) state[i] = false;
for(int i: w.right) state[i] = false;
}
else{
boolean[] temp = new boolean[12];
for(int k = 0; k < 12; k++) temp[k] = false;
for(int i: w.left) temp[i] = true;
for(int i: w.right) temp[i] = true;
for(int i = 0; i < 12; i++){
if(!temp[i]) state[i] = false;
}
}
}
//for(boolean b: state) System.out.print(b + " ");
int targ = -1;
int RL = EVEN;
for(int i = 0; i < 12; i++){
if(!state[i]) continue;
int cnt = 0;
int rl = EVEN;
for(weight w: weights){
//检查i为假币是否合适条件w
if(w.rel == EVEN) continue;
//平的一定符合
boolean inLeft = false, inRight = false;
for(int j: w.left){
if(i == j) {
inLeft = true;
break;
}
}
for(int j: w.right){
if(i == j) {
inRight = true;
break;
}
}
if((inLeft && inRight) || (!inLeft && !inRight)){
//不是解
cnt++;
break;
}
int tempRl;
if(w.rel == UP && inLeft || w.rel == DOWN && inRight) tempRl = HEAVY;
else tempRl = LIGHT;
if(rl + tempRl == 0) {
cnt++;
break;//轻重矛盾。
}
rl = tempRl;
}
//continue;
if(cnt == 0){
targ = i;
RL = rl;
break;
}
}
//这里是一个round
//System.out.println(targ);
System.out.println(((char)(targ +'A')) + " is the counterfeit coin and it is " +
(RL == LIGHT ? "light" : "heavy") + ".");
}
}
}