汉诺塔问题
#include<iostream> using namespace std;
void main()
{
int n;
char a='A',b='B',c='C';
cout<<"输入盘子数:"<<endl;
cin>>n;
void hanoi(int,char,char,char);
hanoi(n,a,b,c);
}
void hanoi(int n,char a,char b,char c)
{
int i=1;
if(n==1) cout<<a<<"-->"<<c<<endl;
else
{
hanoi(n-1,a,c,b);
cout<<a<<"-->"<<c<<endl;
hanoi(n-1,b,a,c);
}
return;
}