-
Notifications
You must be signed in to change notification settings - Fork 0
/
18 J4-S2
53 lines (50 loc) · 1.64 KB
/
18 J4-S2
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
52
53
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] sc = new int[n][n];
for(int i = 0; i < n; i++){
for(int x = 0; x < n; x++){
sc[i][x]= scanner.nextInt();
}
}
//matrix not spined
if(sc[0][0] < sc[0][1] && sc[0][0] < sc[1][0]){
for(int i = 0; i < n; i++){
for(int x = 0; x < n; x++){
System.out.print(sc[i][x]);
}
System.out.println("");
}
}
//matrix spined 90 degrees clockwise
else if(sc[0][n-1] < sc[0][n-2] && sc[0][n-1] < sc[1][n-1]){
for(int i = n-1; i >= 0; i--){
for(int x = 0; x < n; x++){
System.out.print(sc[x][i]);
}
System.out.println("");
}
}
//matrix spined 180 degrees clockwise
else if(sc[n-1][n-1] < sc[n-1][n-2] && sc[n-1][n-1] < sc[n-2][n-1]){
for(int i = n-1; i >= 0; i--){
for(int x = n-1; x >= 0; x--){
System.out.print(sc[i][x]);
}
System.out.println("");
}
}
//matrix spined 270 degrees clockwise
else if(sc[n-1][0] < sc[n-2][0] && sc[n-1][0] < sc[n-1][1]){
for(int i = 0; i < n; i++){
for(int x = n-1; x >= 0; x--){
System.out.print(sc[x][i]);
}
System.out.println("");
}
}
}
}