汉诺塔问题
实现
#include <iostream>
using namespace std;
void hanoi (int n, char a, char b, char c) { // a -> b
if (n == 1) {
printf("%c->%d->%c\n", a, n, b);
return;
}
hanoi(n - 1, a, c, b);
printf("%c->%d->%c\n", a, n, b);
hanoi(n - 1, c, b, a);
}
int main () {
int n;
char a, b, c;
scanf("%d %c %c %c", &n, &a, &b, &c);
hanoi(n, a, b, c);
return 0;
}