#include<iostream>
using namespace std;
void move(char a, char b)
{
cout << a << "->" << b << endl;
};
void funmove(int n, char a, char b, char c)
{
if (n == 1)
move(a, c);
else
{
funmove(n - 1, a, c, b);
move(a, c);
funmove(n - 1, b, a, c);
}
}
int main()
{
int n ;
cout << "输入a柱上要移动圆盘数目:";
cin >> n;
char a = 'a';
char b = 'b';
char c='c';
cout << "移动步骤:";
funmove(n, a, b, c);
}
汉罗塔问题简单实现
最新推荐文章于 2020-12-30 19:34:40 发布