Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
8057 | 吴承熹 | 螺旋矩阵 | C++ | Accepted | 0 MS | 268 KB | 1011 | 2025-06-08 11:13:02 |
#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; }//