-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5052.java
51 lines (41 loc) · 1.55 KB
/
5052.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
46
47
48
49
50
51
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class PhoneNumberList {
static StringBuilder answer;
public static void main(String[] args) throws IOException {
answer = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i = 0; i < t; i++) {
int n = Integer.parseInt(br.readLine());
String[] phoneNumber = new String[n];
Map<String, Integer> map = new HashMap<>();
for(int j = 0; j < n; j++) {
phoneNumber[j] = br.readLine();
map.put(phoneNumber[j], 0);
}
isConsistentList(phoneNumber, map);
}
br.close();
System.out.print(answer.toString());
}
public static void isConsistentList(String[] phoneNumber, Map<String, Integer> map) {
for(int i = 0; i < phoneNumber.length; i++) {
for(int l = 1; l <= phoneNumber[i].length(); l++) {
String subStr = phoneNumber[i].substring(0, l);
if (map.containsKey(subStr)) {
map.put(phoneNumber[i], map.get(phoneNumber[i]) + 1);
if(map.get(phoneNumber[i]) > 1) {
answer.append("NO\n");
return;
}
}
}
map.put(phoneNumber[i], 1);
}
answer.append("YES\n");
}
}