题解
2025-08-22 14:17:38
发布于:上海
1阅读
0回复
0点赞
#include <iostream>
using namespace std;
void hanoi(int n, char from, char to, char aux) {
if (n == 1) {
cout << from << " --" << n << "--> " << to << endl;
return;
}
hanoi(n - 1, from, aux, to);
cout << from << " --" << n << "--> " << to << endl;
hanoi(n - 1, aux, to, from);
}
int main() {
int n;
cin >> n;
hanoi(n, 'A', 'C', 'B');
return 0;
}
这里空空如也
有帮助,赞一个