提交时间:2026-01-04 15:38:03

运行 ID: 81055

#include <iostream> using namespace std; int hanoi(int n, char from, char to, char aux) { if (n == 1) { cout << from << "->" << to << endl; return 1; } int count = 0; count += hanoi(n - 1, from, aux, to); cout << from << "->" << to << endl; count++; count += hanoi(n - 1, aux, to, from); return count; } int main() { int n; cin >> n; int total_moves = hanoi(n, 'A', 'C', 'B'); cout << total_moves << endl; return 0; }