当前位置: 代码迷 >> 综合 >> Hanoi 问题
  详细解决方案

Hanoi 问题

热度:42   发布时间:2023-12-13 04:04:33.0

不解释!

#include <iostream>
using namespace std;void Hanoi(int n, char src, char mid, char dest)
{if(n == 1){cout << src << " -> " << dest<<endl;return;}Hanoi(n-1, src, dest, mid);cout << src << " -> " << dest << endl;Hanoi(n-1, mid, src, dest);return;
}
int main()
{int n;cin >> n;Hanoi(n, 'A', 'B', 'C');return 0;
}