Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
112606 | 刘珩宇 | 螺旋矩阵 | C++ | Wrong Answer | 1 MS | 276 KB | 738 | 2025-03-09 18:50:16 |
#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ int n,i=0,j,t=1; cin>>n; int a[11][11]; while(t<=n*n){ for(j=i;j<=n-i&&t<=n*n;j++){ a[i][j]=t; t++; } for(j=i+1;j<=n-i&&t<=n*n;j++){ a[j][n-i-1]=t; t++; } for(j=n-i-2;j>=i&&t<=n*n;j--){ a[n-i-1][j]=t; t++; } for(j=n-i-2;j>i&&t<=n*n;j--){ a[j][i]=t; t++; } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("%4d",a[i][j]); } cout<<endl; } return 0; }
------Input------
5
------Answer-----
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
------Your output-----
19 20 21 22 23 1845495745632766 0 25 17 08014944 0 8 164742627 08045728 9 15 14 13 12 10