-
Notifications
You must be signed in to change notification settings - Fork 1
/
201412-2.cpp
64 lines (63 loc) · 1.38 KB
/
201412-2.cpp
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
54
55
56
57
58
59
60
61
62
63
64
#include "stdio.h"
int main() {
int n;
int a[500 + 10][500 + 10];
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &a[i][j]);
}
}
int x = 0, y = 0;
int flag = 1;
int state_flag = 1;
for (int i = 0; i < n * n; ++i) {
printf("%d", a[x][y]);
if (i < n * n - 1) {
printf(" ");
}
if (state_flag == 1) {
if (x == 0) {
if (y == n - 1) {
x++;
} else {
y++;
}
flag = 1;
state_flag = 0;
continue;
}
if (y == 0) {
if (x == n - 1) {
y++;
} else {
x++;
}
flag = 0;
state_flag = 0;
continue;
}
if (y == n - 1) {
x++;
flag = 1;
state_flag = 0;
continue;
}
if (x == n - 1) {
y++;
flag = 0;
state_flag = 0;
continue;
}
}
if (flag) {
x++;
y--;
} else {
x--;
y++;
}
state_flag = 1;
}
return 0;
}