| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 148819 | Kevin | 蛇形矩阵 | C++ | Accepted | 0 MS | 276 KB | 392 | 2026-03-01 16:51:20 |
#include<bits/stdc++.h> using namespace std; int a[50][50]; int main() { int n,s=1,x=1,y=1; cin>>n; a[x][y]=1; while(s<n*n) { while(x+1<=n&&a[x+1][y]==0) a[++x][y]=++s; a[x][++y]=++s; while(x-1>=1&&a[x-1][y]==0) a[--x][y]=++s; a[x][++y]=++s; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<setw(3)<<a[i][j]; } cout<<endl; } return 0; }