Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
8056 吴承熹 螺旋矩阵 C++ Wrong Answer 7 MS 264 KB 947 2025-06-08 10:50:43

Tests(5/10):


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+1 : n/2; 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++; } } 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------
19
------Answer-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 20 71 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 90 21 70 135 192 193 194 195 196 197 198 199 200 201 202 203 204 205 152 91 22 69 134 191 240 241 242 243 244 245 246 247 248 249 250 251 206 153 92 23 68 133 190 239 280 281 282 283 284 285 286 287 288 289 252 207 154 93 24 67 132 189 238 279 312 313 314 315 3
------Your output-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 20 71 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 90 21 70 135 192 193 194 195 196 197 198 199 200 201 202 203 204 205 152 91 22 69 134 191 240 241 242 243 244 245 246 247 248 249 250 251 206 153 92 23 68 133 190 239 280 281 282 283 284 285 286 287 288 289 252 207 154 93 24 67 132 189 238 279 312 313 314 315 3