-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q33.java
45 lines (37 loc) · 1.02 KB
/
Q33.java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Q33 {
public static void main (String[] args) throws IOException {
System.setProperty("file.encoding", "UTF-8");
BufferedReader br = new BufferedReader(new FileReader("q33.csv"));
// ヘッダを読み飛ばす
br.readLine();
final int SIZE = 100;
String[] kami = new String[SIZE];
String[] simo = new String[SIZE];
for (int i = 0; i < SIZE; i++) {
String[] line = br.readLine().split(",");
kami[i] = line[3];
simo[i] = line[4];
}
br.close();
System.out.println(solve(kami) + solve(simo));
}
public static int solve (String[] strs) {
int ans = 0;
for (int i = 0; i < strs.length; i++) {
cnt:
for (int cnt = 1; ; cnt++) {
String head = strs[i].substring(0, cnt);
for (int j = 0; j < strs.length; j++) {
if (i == j) continue;
if (strs[j].startsWith(head)) continue cnt;
}
ans += cnt;
break;
}
}
return ans;
}
}