-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ1141.java
More file actions
44 lines (35 loc) · 1.07 KB
/
Copy pathJ1141.java
File metadata and controls
44 lines (35 loc) · 1.07 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
package TIL;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
public class J1141 {
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(buffer.readLine());
String[] array = new String[N];
for (int i = 0 ; i < N; i++){
array[i] = buffer.readLine();
}
Arrays.sort(array,(a,b) -> b.length() - a.length());
HashSet<String> set = new HashSet<>();
for (String s1 : array) {
if (set.size() == 0) {
set.add(s1);
continue;
}
boolean flag = true;
for (String s2 : set) {
if (s2.indexOf(s1) == 0) {
flag = false;
break;
}
}
if (flag) {
set.add(s1);
}
}
System.out.println(set.size());
}
}