Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
149284 郑雨心 蛇形矩阵 C++ Presentation Error 0 MS 268 KB 427 2026-03-08 19:53:46

Tests(0/10):


Code:

#include <iostream> using namespace std; int a[15][15]; int main() { int n; cin>>n; int x=1,y=1,s=0; a[x][y]=1; s++; 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<<a[i][j]<<" "; } cout<<endl; } return 0; }