-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefix.java
More file actions
44 lines (40 loc) · 1.3 KB
/
Copy pathPrefix.java
File metadata and controls
44 lines (40 loc) · 1.3 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 algorithm.baek.sort;
import algorithm.TestCase;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Comparator;
/**
* https://www.acmicpc.net/problem/1141
* 접두사
*/
public class Prefix implements TestCase {
@Override
public void test() throws ParseException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] arr = new String[n];
for (int i = 0; i < n; i++) arr[i] = br.readLine();
int cnt = 0;
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.length() == o2.length()) return o1.compareTo(o2);
return o1.length() - o2.length();
}
});
for (int i = 0; i < n; i++) {
boolean flag = true;
for (int j = i + 1; j < n; j++) {
if (arr[j].startsWith(arr[i])) {
flag = false;
break;
}
}
if (flag) cnt++;
}
System.out.println(cnt);
}
}