Run ID:2993

提交时间:2024-03-16 12:41:44

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