解题思路:
注意事项:
参考代码:
#include <iostream> using namespace std; void move(int &n, char &x, char &y) { //执行移动盘子的操作 printf("Move %d from %c to %c\n", n, x, y); } void hanoi(int n,char one, char two, char three) { //将n个盘从one座借助two座,移到three座 if(n==1) {//只有 1 个盘直接移,不需要借助 move(n, one, three); } else { hanoi(n-1, one, three, two); move(n, one, three); hanoi(n-1, two, one, three); } } int main() { int n; scanf("%d",&n); hanoi(n, '1', '2', '3'); return 0; }
0.0分
5 人评分
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:647 |
校门外的树 (C语言代码)浏览:692 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |
C二级辅导-阶乘数列 (C语言代码)浏览:508 |
简单的a+b (C语言代码)浏览:415 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:473 |
【出圈】 (C++代码)简单循环浏览:628 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:695 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:444 |
明明的随机数 (C语言代码)浏览:613 |