-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphonelist.java
25 lines (23 loc) · 956 Bytes
/
phonelist.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
import java.io.*;
import java.util.*;
import java.math.*;
public class phonelist {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(in.readLine());
for(int i = 0; i < n; i++) {
boolean status = true;
int phones = Integer.parseInt(in.readLine());
ArrayList<String> numeros = new ArrayList<String>();
for(int p = 0; p < phones; p++) numeros.add(in.readLine());
Collections.sort(numeros);
for(int j = 0; j < numeros.size() - 1; j++) {
if(numeros.get(j + 1).indexOf(numeros.get(j)) == 0) status = false;
}
if(status) out.println("YES");
else out.println("NO");
}
out.close();
}
}