Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
8073 | 邓小龙 | 数字方阵 | C++ | Accepted | 4 MS | 268 KB | 864 | 2025-06-13 14:42:22 |
#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; } for(int i=z+1;i<=n-z+1;i++){ a[i][n-z+1]=c; } for(int j=n-z;j>=z;j--){ a[n-z+1][j]=c; } for(int i=n-z;i>=z+1;i--){ a[i][z]=c; } c++; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<a[i][j]<<" "; } cout<<endl; } return 0; }