You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
716 B
34 lines
716 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 40;
|
|
int n;
|
|
int g[N][N];
|
|
|
|
int main() {
|
|
cin >> n;
|
|
int r = 1;
|
|
int c = n / 2 + 1;
|
|
g[r][c] = 1;
|
|
|
|
for (int i = 2; i <= n * n; i++) {
|
|
if (r == 1 && c != n)
|
|
r = n, c++;
|
|
else if (c == n && r != 1)
|
|
r--, c = 1;
|
|
else if (r == 1 && c == n)
|
|
r = 2;
|
|
else if (r != 1 && c != n) {
|
|
if (g[r - 1][c + 1] == 0)
|
|
r--, c++;
|
|
else
|
|
r++;
|
|
}
|
|
g[r][c] = i;
|
|
}
|
|
|
|
for (int i = 1; i <= n; i++, puts(""))
|
|
for (int j = 1; j <= n; j++)
|
|
printf("%d ", g[i][j]);
|
|
return 0;
|
|
} |