Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
93116 | Kevin | 蛇形矩阵 | C++ | Accepted | 1 MS | 196 KB | 444 | 2024-10-10 15:33:34 |
#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(x+1<n&&!a[x+1][y]) a[++x][y]=++tot; a[x][++y]=++tot; while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot; a[x][++y]=++tot; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ printf("%3d",a[i][j]); } printf("\n"); } return 0; }