Run ID:2989

提交时间:2024-03-16 12:36:00

#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; }