酷代码 AI
菜单
服务商

将上题用C++

```cpp #include <iostream> using namespace std; long long moves = 0; void hanoi(int n, char source, char target, char auxiliary) { if (n == 1) { cout << source << "->1->" << target << endl; moves++; } else { hanoi(n - 1, source, auxiliary, target); cout << source << "->" << n << "->" << target << endl; moves++; hanoi(n - 1, auxiliary, target, source); } } int main() { int N; cin >> N; moves = 0; hanoi(N, 'a', 'c', 'b'); cout << moves << endl; return 0; } ``` [2026-01-05 17:53:37 | AI问答 | 165点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多