B3940填幻方WA0分求助

题目总版

XY_guiling_ @ 2024-11-08 18:25:42

#include<bits/stdc++.h>
using namespace std;
int a[25][25],dqhang,dqlie;
int main(){
    int n;cin>>n;
    a[1][(n/2)+1]=1;
    dqhang=1;dqlie=((n/2)+1);
    for(int i=2;i<=n*n;i++){
        if(dqhang-1)dqhang--;
        else dqhang=n;
        if(dqlie+1<=n)dqlie++;
        else dqlie=1;
        if(!a[dqhang][dqlie])a[dqhang][dqlie]=i;
        else{
            if(dqhang+1<=n)dqhang++;
            else dqhang=0;
            a[dqhang][dqlie]=i;
        }
    }for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<a[i][j]<<" ";
        }cout<<endl;
    }
}

|