Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
93115 | Kevin | 螺旋矩阵 | C++ | Accepted | 1 MS | 196 KB | 495 | 2024-10-10 15:23:16 |
#include<cstdio> #include<cstring> #define maxn 21 int a[maxn][maxn]; int main() { int n,x,y,tot; scanf("%d",&n); memset(a,0,sizeof(a)); tot=a[x=0][y=0]=1; while(tot<n*n){ while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot; while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot; while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot; while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ printf("%4d",a[i][j]); } printf("\n"); } return 0; }