#include <stdio.h>
void _move(int m, char p, char q, char r);
int main() {
int n;
puts("Please input the number of dish.");
scanf("%d", &n);
printf("The step of moving %d dishies on the three pillars is:\n", n);
_move(n, 'A', 'B', 'C');
return 0;
}
void _move(int m, char p, char q, char r) {
static int step = 1;
if (m == 1) {
printf("[%d] move 1 # from %c to %c\n", step, p, r);
step++;
} else {
_move(m - 1, p, r, q);
printf("[%d] move %d # from %c to %c\n", step, m, p, r);
step++;
_move(m - 1, q, p, r);
}
}
经典Hanoi问题
最新推荐文章于 2024-04-20 19:46:01 发布
