汉诺塔
来源:互联网 发布:linux exec() 编辑:程序博客网 时间:2024/04/29 09:17
#include <stdio.h>void Move(int n,char a,char b){ printf("Move %d : from %c to %c\n",n,a,b);}//函数功能:用递方法将n个圆盘借助于柱子c从源柱子a移动到目标柱子b上void Hanoi(int n,char a,char b,char c){ if(n == 1) { Move(n,a,b);//将第n个圆盘由a移动到b } else{ Hanoi(n-1,a,c,b);//将第n-1个圆盘借助于b由a移动到c Move(n,a,b);//将第n个圆盘由a移动到b Hanoi(n-1,c,b,a);//将第n-1个圆盘借助于a由c移动到b }}int main(){ int n; printf("Input the number of disks:\n"); scanf("%d",&n); printf("Steps of moving %d disks from A to B by means of C:\n", n); Hanoi(n,'A','B','C');//将n个圆盘借助C由A转移到B}
其实我没有搞懂,直接从书上搬来
1 0
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- WordPress主题支持导航菜单
- map = new TreeMap<String, List<String>>().descendingMap();
- 我的OC练习(二):创建类的小“意外”
- QWS_MOUSE_PROTO该如何写
- 2015.11.07_07_03_Linux文件查找详解
- 汉诺塔
- 从IT到DT:数据比你更靠谱
- 在MYSQL中存储数组
- win8电脑右键无响应,右键很慢,右键卡死解决
- Anroid Activity方向锁定及其横竖屏切换
- 使徒行者:痛苦,源自于心中的使命
- atoi
- 转码与重定向的区别之于SpringMVC
- 2..第二篇:常用算法之数学算法-----最大公约数和最小公倍数