Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
118678 马珺宇 螺旋矩阵 C++ Time Limit Exceeded 1000 MS 308 KB 550 2025-05-10 09:37: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; }