Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
8058 吴承熹 数字方阵 C++ Wrong Answer 0 MS 264 KB 1017 2025-06-08 11:13:56

Tests(0/2):


Code:

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


Run Info:

------Input------
5
------Answer-----
1 1 1 1 1 1 2 2 2 1 1 2 3 2 1 1 2 2 2 1 1 1 1 1 1
------Your output-----
1 1 1 1 1 3 4 4 4 1 2 4 5 4 1 1 4 4 4 1 1 1 1 1 1