Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
6781 张育斌 螺旋矩阵 C++ Wrong Answer 0 MS 268 KB 814 2025-03-15 15:32:51

Tests(0/10):


Code:

#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<bits/stdc++.h> #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ int n,a[21][21]; int k=(n+1)/2; int q=k; int t=1; cin>>n; for(k=1;k<=(n+1)/2;k++){ for(int j=k;j<=n-k+1;j++) a[k][j]=t++; for(int i=q-k+2;i<=n-k+1;i++) a[i][n-k+1]=t++; for(int j=n-k;j>=k;j--) a[n-k+1][j]=t++; for(int i=n-k;i>=k+1;i--) a[i][k]=t++; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<setw(4)<<a[i][j]; if(j==n) cout<<endl; } } return 0; }


Run Info:

------Input------
1
------Answer-----
1
------Your output-----
2