|
|
|
@ -1,26 +0,0 @@
|
|
|
|
|
#include<iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
void HN(int n, char A, char B, char C)
|
|
|
|
|
{
|
|
|
|
|
if (n == 1)
|
|
|
|
|
{ //起始位置只剩下一个时,直接移动到目的地(第二步,最后一个盘子移动到C)
|
|
|
|
|
cout << A << "->" << C << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
HN(n - 1, A, C, B); //把A上面的盘子,中转为C,移动到B (就是第一步,把盘子移动到B)
|
|
|
|
|
cout << A << "->" << C << endl;
|
|
|
|
|
HN(n - 1, B, A, C); //把B上面的盘子,中转为A,移动到C(第三步,B上的盘子移动到C)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
cout << "请输入A上有几个按顺序排好的碟子:";
|
|
|
|
|
cin >> n;
|
|
|
|
|
cout << "移动顺序如下\n";
|
|
|
|
|
HN(n, 'A', 'B', 'C');
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|