关于蛇形填数问题求解
2015-12-11 17:35
274 查看
在n*n方阵里填入1, 2, 3, 4, 5...........n*n,填成蛇形,如:
n = 4时
10 11 12 1
9 16 13 2
8 15 14 3
7 6 5 4
代码如下
检查结果;
Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: C:\Documents and Settings\Administrator\My Documents\未命名1.exe
- Output Size: 500.2529296875 KiB
- Compilation Time: 0.34s
运行时输入n后
结果却是一片空白
是不是哪里有错
求指导
谢谢
n = 4时
10 11 12 1
9 16 13 2
8 15 14 3
7 6 5 4
代码如下
#include <cstdio> #include <cstring> #define MAXN 10 int a[MAXN][MAXN]; //using namespace std; int main() { int n, x, y, m, tot; //cin >> n; scanf("%d",&n); memset(a, 0, sizeof(a)) ;//数组清零 tot = a[x=0][y=n-1]=1; while(tot<n*m) { while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot; while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot; while(x-1>=0&&!a[x-1][y]) a[x][--y]=++tot; while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot; } for(int i=0;i<n;++i) { for(int j=0;j<n;++j) printf("%3d", a[i][j]); printf("\n"); } return 0; }
检查结果;
Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: C:\Documents and Settings\Administrator\My Documents\未命名1.exe
- Output Size: 500.2529296875 KiB
- Compilation Time: 0.34s
运行时输入n后
结果却是一片空白
是不是哪里有错
求指导
谢谢
相关文章推荐
- python中调用matlab函数
- PHP 文件校验 文件的 MD5 散列值
- 推荐一个PHP在线代码运行的网站
- windows禅道环境搭建
- Swift 函数做参数和闭包做参数的一个细节差别
- zoj 3672 思考题
- c++ 异常 warning: 'MEMORY_UNIT_NAME' defined but not used
- UE4的NetWork简单原理
- 合并两个dataset
- MVC + EF 框架 对数据库做增删改查
- 网络 TCP 三次握手四次挥手
- java web 学习-filter简介
- ExecutorService引发的血案(三)ThreadPoolExecutor
- poj 1283 Moving Computer dp解小球放小盒
- 51nod 1449 砝码称重 (二进制思想)
- 修改MFC主窗口标题
- 2003-can't connect to mysql server on 'localhost'(10061)
- android监听html事件
- java使用split分隔,需要注意的点
- NSDictionary (字典API+排序)