数学真难解
2024-09-24 22:32:48
发布于:云南
10阅读
0回复
0点赞
直接看了看AC君的代码啊
#include<bits/stdc++.h>
using namespace std;
int a[45][45];
int main(){
    int n; cin >> n;
    int x = 1,y = (n + 1) >> 1;
    for(int i = 1;i <= n * n;i++){
        a[x][y] = i;
        if(a[(x - 2 + n) % n + 1][y % n + 1] == 0){
            x = (x - 2 + n) % n + 1;
            y = y % n + 1;
        }else x = x % n + 1;
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++) cout << a[i][j] << " ";
        cout << endl;
    }
    return 0;
}
这里空空如也







有帮助,赞一个