Repository navigation
Expand file tree
/
Copy pathNameCompatibility.java
More file actions
59 lines (49 loc) · 1.99 KB
/
Copy pathNameCompatibility.java
File metadata and controls
59 lines (49 loc) · 1.99 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
package implementation;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class NameCompatibility {
static int[] engHeck = {3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String first_name = br.readLine();
String second_name = br.readLine();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < first_name.length(); i++) {
sb.append(Character.toString(first_name.charAt(i)));
sb.append(Character.toString(second_name.charAt(i)));
}
String full_name = sb.toString();
List<Integer> name_num_list = new ArrayList<>();
for (int i = 0; i < full_name.length(); i++) {
name_num_list.add(engHeck[(full_name.charAt(i)) - 65]);
}
List<Integer> result_list = new ArrayList<>();
while (true) {
for (int i = 0; i < name_num_list.size() - 1; i++) {
int hap = name_num_list.get(i) + name_num_list.get(i + 1);
if (hap >= 10) {
String hap_string = Integer.toString(hap);
result_list.add(hap_string.charAt(hap_string.length() - 1) - '0');
}
else {
result_list.add(hap);
}
}
if (result_list.size() == 2) {
break;
}
name_num_list.clear();
for (int i = 0; i < result_list.size(); i++) {
name_num_list.add(result_list.get(i));
}
result_list.clear();
}
bw.write(Integer.toString(result_list.get(0)) + Integer.toString(result_list.get(1)));
bw.flush();
bw.close();
br.close();
}
}