解题思路:
朝一个方向走,到边界就转,走过的标记过了就不走了。
注意事项:
注意输出格式
参考代码
#include<bits/stdc++.h> using namespace std; const int maxn = 103; int a[maxn][maxn]; int main() { int n,x,y,tot=0; while(scanf("%d",&n)==1) { memset(a,0,sizeof(a)); tot = a[x=0][y=n-1]=1; while(tot<n*n) { while(x+1<n&&!a[x+1][y]) a[++x][y] = ++tot; //向下 while(y-1>=0&&!a[x][y-1]) a[x][--y] = ++tot; //left while(x-1>=0&&!a[x-1][y]) a[--x][y] = ++tot; //up while(y+1<n&&!a[x][y+1]) a[x][++y] = ++tot; //right } for(x = 0; x<n;x++) { for(y=0;y<n;y++) if(y==n-1) printf("%d\n", a[x][y]); else printf("%d ", a[x][y]); } putchar('\n'); } return 0; }
0.0分
0 人评分
校门外的树 (C语言代码)浏览:957 |
【偶数求和】 (C语言代码)浏览:640 |
兰顿蚂蚁 (C++代码)浏览:1044 |
1908题解浏览:636 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:543 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1420 |
演讲大赛评分 (C语言代码)浏览:1629 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:509 |
陈教主的三角形 (C语言代码)浏览:1141 |
链表数据求和操作 (C语言代码)浏览:942 |