Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
2968 孙浚轩 螺旋矩阵 C++ Accepted 0 MS 284 KB 732 2024-03-15 13:14:55

Tests(10/10):


Code:

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