File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+ import java .text .*;
4
+ import java .math .*;
5
+ import java .util .regex .*;
6
+
7
+ public class Solution {
8
+
9
+ public static void main (String [] args ) {
10
+ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
11
+ Scanner scan = new Scanner (System .in );
12
+ int count = scan .nextInt ();
13
+ for (int i = 0 ; i < count ; i ++) {
14
+ int N = scan .nextInt ();
15
+ char [][] G = new char [N ][N ];
16
+ for (int j = 0 ; j < N ; j ++) {
17
+ String line = scan .next ();
18
+ for (int k = 0 ; k < N ; k ++) {
19
+ G [j ][k ] = line .charAt (k );
20
+ }
21
+ Arrays .sort (G [j ]);
22
+ }
23
+ boolean possible = true ;
24
+ for (int j = 0 ; j < N && possible ; j ++) {
25
+ for (int k = 1 ; k < N && possible ; k ++) {
26
+ if (Character .compare (G [k ][j ], G [k -1 ][j ]) < 0 ) possible = false ;
27
+ }
28
+ }
29
+ System .out .println (possible ? "YES" : "NO" );
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments