额e
2023-12-03 20:59:59
发布于:广东
6阅读
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;
}
全部评论 1
e
2023-12-03 来自 广东
0
有帮助,赞一个