-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp65.java
42 lines (39 loc) · 949 Bytes
/
dcp65.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
import java.util.Scanner;
class Dcp65 {
public static void clockwise(int n, int m, int[][] ar ) {
for (int j = m; j < ar[0].length-m; j++) {
System.out.print(ar[n][j] + " ");
}
for (int j = n+1; j < ar.length-n; j++) {
System.out.print(ar[j][ar[0].length-m-1] + " ");
}
for (int j = ar[0].length-m-2; j >= m; j--) {
System.out.print(ar[ar.length-n-1][j] + " ");
}
for (int j = ar.length-n-2; j > n; j--) {
System.out.print(ar[j][m] + " ");
}
if (ar.length > ar[0].length) {
if (m == ar.length - ar[0].length)
return;
}
else{
if (n == ar[0].length - ar.length)
return;
}
clockwise(n+1,m+1,ar);
return;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] ar = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ar[i][j] = sc.nextInt();
}
}
clockwise(0,0,ar);
}
}