#include using namespace std;

void hanoi(int n, char a, char b, char c) { if (n == 1) { cout << 'Move disk 1 from ' << a << ' to ' << c << endl; } else { hanoi(n-1, a, c, b); cout << 'Move disk ' << n << ' from ' << a << ' to ' << c << endl; hanoi(n-1, b, a, c); } }

int main() { int n; cout << 'Enter the number of disks: '; cin >> n;

hanoi(n, 'A', 'B', 'C');

return 0;

}

C++ 汉诺塔问题算法实现

原文地址: https://www.cveoy.top/t/topic/n44v 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录