汉诺塔_百度百科 (baidu.com)https://baike.baidu.com/item/%E6%B1%89%E8%AF%BA%E5%A1%94/3468295
//
// Created by zzh on 2024/8/6.
//
//汉诺塔问题
#include<stdio.h>
void move(char x, char y) {
printf("%c --> %c \n", x, y);
}
int hanoi(int count, int n, char one, char two, char three) {
//将n个盘从one座借助two座移动到three座
count = count + 1;
if (n == 1) {
move(one, three);
} else {
count = hanoi(count, n - 1, one, three, two);
move(one, three);
count = hanoi(count, n - 1, two, one, three);
}
return count;
}
int main() {
int m;
int count;
printf("input the number of disks:");
scanf("%d", &m);
printf("The step to move %d disks:\n", m);
count = hanoi(0, m, 'A', 'B', 'C');
printf("the times of moving disks is %d \n", count);
return 0;
}