#include<iostream>
using namespace std;
int i = 0;
void Hanoi(int count, int start, int end, int temp)
{
if(count>0){
Hanoi(count - 1, start, temp, end);
i++;
cout <<"第"<<i<< "步 将第 " << count << "个盘子从第" << start << "移到" << end << endl;
//Hanoi(1, start, end, temp);
Hanoi(count - 1, temp, end, start);
return;
}
}
int main()
{
int count;
while (cin >> count)
{
i = 0;
Hanoi(count, 1, 3, 2);
cout << "总步数"<<i<<endl;
}
}
[C++]Hanoi
最新推荐文章于 2022-03-24 21:07:33 发布