文件目录

#include <iostream>
using namespace std;
int main()
{
    int n = 3;
    cin >> n;
    int a[50][50] = {};
    int x = 1, y = (n + 1) / 2;
    for (int i = 1; i <= n * n; i++)
    {
        a[x][y] = i;
        // cout << x << " " << y << " " << i << endl;
        int xx = x - 1;
        if (xx < 1)
            xx = n;
        int yy = y + 1;
        if (yy > n)
            yy = 1;
        if (a[xx][yy])
        {
            xx = x + 1;
            if (xx > n)
                xx = 1;
            yy = y;
        }
        x = xx;
        y = yy;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}