-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2018j4s2.java
50 lines (48 loc) · 1.09 KB
/
2018j4s2.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
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int table[][] = new int[n][n];
boolean table_correct = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
table[i][j] = in.nextInt();
}
}
while (true) {
table_correct = true;
table = rotate_array(table, n);
for (int i = 0; i < n - 1; i++) {
if (!(table[0][i] < table[0][i + 1])) {
table_correct = false;
}
}
for (int i = 0; i < n - 1; i++) {
if (!(table[i][0] < table[i + 1][0])) {
table_correct = false;
}
}
if (table_correct) {
// print table
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
System.out.print(table[i][j] + " ");
}
System.out.println(table[i][n - 1]);
}
break;
}
}
}
// rotate array clockwise
public static int[][] rotate_array(int[][] t, int n) {
int new_t[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
new_t[n - 1 - j][i] = t[i][j];
}
}
return new_t;
}
}