90分,#2WA了
查看原帖
90分,#2WA了
1399098
JinHc1218楼主2024/8/4 10:35

求帮助。

#include<bits/stdc++.h>
using namespace std;
int a[39][39];
int main(){
    int n;
    cin >> n;
    int x = n / 2, y = 0, p = 1, t = n * n;
    a[x][y] = p;
    while(p <= t){
        x++; y--;
        if(x == n && y < 0){
            x--; y += 2;
        }
        else if(x == n) x = 0;
        else if(y < 0) y = n - 1;
        else if(a[x][y]){
            x--; y += 2;
        }
        a[x][y] = ++p;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << a[j][i] << ' ';
        }
        cout << endl;
    }
    return 0;
}
2024/8/4 10:35
加载中...