Repository navigation
Expand file tree
/
Copy pathSecretLetter.java
More file actions
69 lines (60 loc) · 2.24 KB
/
Copy pathSecretLetter.java
File metadata and controls
69 lines (60 loc) · 2.24 KB
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class SecretLetter {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Map<String, String> map = new HashMap<>();
map.put("A", "000000");
map.put("B", "001111");
map.put("C", "010011");
map.put("D", "011100");
map.put("E", "100110");
map.put("F", "101001");
map.put("G", "110101");
map.put("H", "111010");
StringBuffer sb = new StringBuffer();
String input = br.readLine();
String numArrInput = br.readLine();
for (int i = 0; i < numArrInput.length(); i += 6) {
String sub = numArrInput.substring(i, i + 6);
if (map.get("A").equals(sub) || isCheck(sub, map.get("A"))) {
sb.append("A");
} else if (map.get("B").equals(sub) || isCheck(sub, map.get("B"))) {
sb.append("B");
} else if (map.get("C").equals(sub) || isCheck(sub, map.get("C"))) {
sb.append("C");
} else if (map.get("D").equals(sub) || isCheck(sub, map.get("D"))) {
sb.append("D");
} else if (map.get("E").equals(sub) || isCheck(sub, map.get("E"))) {
sb.append("E");
} else if (map.get("F").equals(sub) || isCheck(sub, map.get("F"))) {
sb.append("F");
} else if (map.get("G").equals(sub) || isCheck(sub, map.get("G"))) {
sb.append("G");
} else if (map.get("H").equals(sub) || isCheck(sub, map.get("H"))) {
sb.append("H");
} else {
sb = new StringBuffer();
sb.append(i / 6 + 1);
break;
}
}
System.out.println(sb.toString());
}
static boolean isCheck(String sub, String numArrInput) {
int cnt = 0;
for (int i = 0; i < sub.length(); i++) {
if (sub.charAt(i) != numArrInput.charAt(i)) {
cnt++;
}
}
if (cnt == 1) {
return true;
}
else {
return false;
}
}
}