Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
113941 郝王骏程 螺旋矩阵 C++ Wrong Answer 2 MS 308 KB 696 2025-03-17 20:28:14

Tests(0/10):


Code:

#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,a[101][101]={0},t=1,i=0; cin>>n; while(t<=n*n){ for(int j=i;j<n-i&&t<=n*n;j++)a[i][j]=t++; for(int j=i+1;j<n-i&&t<=n*n;j++)a[j][n-i-1]=t++; for(int j=-i-2;j>=i&&t<=n*n;j--)a[n-i-1][j]=t++; for(int j=-i-2;j>i&&t<=n*n;j--)a[i][j]=t++; } for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ printf("%4d",a[i][j]); cout<<endl; } } return 0; }


Run Info:

------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 0 0 0 0 0 24 0 0 0 0 0 25 0 0 0 0 0 17 0 0 0 0 0 18 0 0 0 0 0 0 0