-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListEx.java
More file actions
44 lines (38 loc) · 1.4 KB
/
Copy pathArrayListEx.java
File metadata and controls
44 lines (38 loc) · 1.4 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int c;
List<List<Character>> ls = new ArrayList<List<Character>>();
List<Character> tm = new ArrayList<Character>();
String tmp;
boolean result = true;
for (int i=0; i<n; i++){
ls.clear();
c = in.nextInt();
//System.out.println(c);
tmp = in.nextLine();
for (int j =0; j<c; j++){
tmp = in.nextLine();
tm = new ArrayList<Character>();
//System.out.println(tmp);
for (int k=0; k<c; k++)
tm.add(tmp.charAt(k));
Collections.sort(tm);
ls.add(tm);
//System.out.println(tm);
}
result = true;
for (int j =0; j<c-1; j++){
//System.out.println(ls);
for (int k=0; k<c; k++){
if (ls.get(j).get(k) > ls.get(j+1).get(k)) result = false;
}
}
if (result) System.out.println("YES"); else System.out.println("NO");
}
}
}