#include <iostream>
using namespace std;
void hano(int n,char a,char b,char c)
{
static int cnt=0;
if(n>0)
{
hano(n-1,a,c,b);//move n-1 disk from a to c
cout<<++cnt<<'/t';
cout<<n<<":"<<a<<"=>"<<c<<endl;
hano(n-1,b,a,c);
}
}
int main()
{
int n;
cout<<"enter a number of disk(s):";
cin>>n;
hano(n,'A','B','C');
}
汉诺塔
最新推荐文章于 2023-07-23 13:04:12 发布