Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
2989 邓小龙 数字方阵 C++ Accepted 0 MS 264 KB 535 2024-03-16 12:36:00

Tests(2/2):


Code:

#include<iostream> using namespace std; int main(){ int n,a[10][10]; cin>>n; int x=0,y=0,x1=0,x2=n-1,y1=0,y2=n-1,i=0; while(i++<=(n+1)/2){ for(x=x1;x<=x2;x++) a[y][x]=i; y1++,x=x2; for(y=y1;y<=y2;y++) a[y][x]=i; x2--,y=y2; for(x=x2;x>=x1;x--) a[y][x]=i; y2--,x=x1; for(y=y2;y>=y1;y--) a[y][x]=i; x1++,y=y1; } for(y=0;y<n;y++){ for(x=0;x<n;x++) cout<<a[y][x]<<" "; cout<<endl; } return 0; }