全员RE
查看原帖
全员RE
1384723
monbigkey楼主2025/6/29 12:22
#include<bits/stdc++.h>
using namespace std;
int a[22][22];
bool empty(int n){
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            if(a[i][j] == 0){
                return false;
            }
        }
    }
    return true;
}
int main()
{
    int N,x,y,num;
    cin >> N;
    a[1][N / 2 + 1] = 1;
    num = 1;
    x = N / 2 + 1;
    y = 1;
    while(!empty(N)){
        if(y == 1){
            y = N;
        }
        else{
            y += 1;
        }
        if(x = 1){
            x = N;
        }
        else{
            x -= 1;
        }
        if(a[x][y] != 0){
            if(y = N){
                y = 1;
            }
            else{
                y--;
            }
        }
        a[x][y] = num + 1;
        num++;
    }
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= N;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

求调

2025/6/29 12:22
加载中...