题解,较简便
2023-06-18 12:22:56
发布于:广东
52阅读
0回复
0点赞
#include <iostream>
using namespace std;
const int N = 40;
int n;
int a[N][N];
int main()
{
cin >> n;
int x = 0, y = n / 2;
for (int i = 1; i <= n * n; i ++ )
{
a[x][y] = i;
int tx = (x - 1 + n) % n, ty = (y + 1) % n;
if (a[tx][ty])
x ++ ;
else
{
x = tx, y = ty;
}
}
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ )
{
printf("%d%c", a[i][j], " \n"[j == n - 1]);
}
}
return 0;
}
这里空空如也
有帮助,赞一个