提交时间:2024-05-05 09:04:18

运行 ID: 39654

#include <bits/stdc++.h> using namespace std; int n,s[105][105],x,y,t; int main(){ cin>>n; x=1; y=n; t=n*n; s[x][y]=t; t--; while(t){ while(x+1<=n&&s[x+1][y]==0){ x++; s[x][y]=t; t--; } while(y+1<=n&&s[x+1][y]==0){ y++; s[x][y]=t; t--; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<s[i][j]<<" "; } cout<<endl; } return 0; }