Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
118677 马珺宇 蛇形矩阵 C++ Wrong Answer 1 MS 312 KB 550 2025-05-10 09:36:24

Tests(0/10):


Code:

#include<bits/stdc++.h> using namespace std; int main(){ int a[101][101]={},i=1,n,b=1; cin>>n; while(b<=n*n){ for(int j=i-1;j<=n-i-1&&b<=n*n;j++){ a[i-1][j]=b++; } for(int j=i-1;j<=n-i-1&&b<=n*n;j++){ a[j][n-i]=b++; } for(int j=n-i;j>=i&&b<=n*n;j--){ a[n-i][j]=b++; } for(int j=n-i;j>=i&&b<=n*n;j--){ a[j][i-1]=b++; } i++; } for(int i=0;i<n;i++){ bool first=0; for(int j=0;j<n;j++){ if(first){ cout<<" "; } cout<<a[i][j]; first=1; } cout<<endl; } return 0; }


Run Info:

------Input------
4
------Answer-----
1 8 9 16 2 7 10 15 3 6 11 14 4 5 12 13
------Your output-----
1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7