-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_1470.java
More file actions
53 lines (45 loc) · 1.26 KB
/
Task_1470.java
File metadata and controls
53 lines (45 loc) · 1.26 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
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class Task_1470 {
private static int[][] res;
private static int N;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
N = s.nextInt();
res = new int[N][N];
f1(0, 0, 1);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(res[i][j] + " ");
}
System.out.println();
}
}
private static void f1(int i, int j, int k) {
for (int l = j; l < N - j - 1; l++) {
res[i][l] = k;
k += 1;
}
if (k < N * N) f2(i, N - j - 1, k);
}
private static void f2(int i, int j, int k) {
for (int l = i; l < N - i - 1; l++) {
res[l][j] = k;
k += 1;
}
if (k < N * N) f3(N - i - 1, j, k);
}
private static void f3(int i, int j, int k) {
for (int l = j; l > N - j - 1; l--) {
res[i][l] = k;
k += 1;
}
if (k < N * N) f2(i, N - j - 1, k);
}
private static void f4(int i, int j, int k) {
for (int l = i; l > N - i - 1; l--) {
res[l][j] = k;
k += 1;
}
if (k < N * N) f3(N - i - 1, j, k);
}
}