Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
158325 陈襗葳 方阵填数 C++ Accepted 1 MS 276 KB 838 2026-08-20 18:19:27

Tests(3/3):


Code:

#include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; int a[101][101]; int top=0,bottom=N-1,left=0,right=N-1; int n=1; while(n<=N*N){ for(int i=top;i<=bottom && n<=N*N;i++){ a[i][right]=n; n++; } right--; for(int i=right;i>=left && n<=N*N;i--){ a[bottom][i]=n; n++; } bottom--; for(int i=bottom;i>=top && n<=N*N;i--){ a[i][left]=n; n++; } left++; for(int i=left;i<=right && n<=N*N;i++){ a[top][i]=n; n++; } top++; } for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cout<<a[i][j]<<" "; } cout<<endl; } return 0; }