Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
77954 | 牛延希 | 螺旋矩阵 | C++ | Accepted | 1 MS | 288 KB | 611 | 2024-06-15 17:49:07 |
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,p,q,a[101][101]; cin>>n; int x=-1,y=n-1,s=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]=0; } }for(int i=1;i<=n/2+1;i++){ while(a[x+1][y]==0 && x+1<=n-1){ a[++x][y]=++s; }while(a[x][y-1]==0 && y-1>=0){ a[x][--y]=++s; }while(a[x-1][y]==0 && x-1>=0){ a[--x][y]=++s; }while(a[x][y+1]==0 && y+1<=n-1){ a[x][++y]=++s; } }for(int i=n-1;i>=0;i--){ for(int j=0;j<n;j++){ printf("%4d",a[j][i]); }cout<<endl; } return 0; }