作者在 2008-10-17 17:52:49 发布以下内容
#include<iostream>
using namespace std;
int main()
{while(1){
int n; void henei(int a,char one,char two,char three);
cout<<"你要求几块的河内塔"<<endl;
cin>>n;
henei(n,'A','B','C');}
return 0;
}
void henei(int a,char one,char two,char three)
{void move(char x,char y);
if(a==1)move(one,three);
else
{henei(a-1,one,three,two);
move(one,three);
henei(a-1,two,one,three);
}}
void move(char x,char y)
{cout<<x<<"--->"<<y<<endl;}
using namespace std;
int main()
{while(1){
int n; void henei(int a,char one,char two,char three);
cout<<"你要求几块的河内塔"<<endl;
cin>>n;
henei(n,'A','B','C');}
return 0;
}
void henei(int a,char one,char two,char three)
{void move(char x,char y);
if(a==1)move(one,three);
else
{henei(a-1,one,three,two);
move(one,three);
henei(a-1,two,one,three);
}}
void move(char x,char y)
{cout<<x<<"--->"<<y<<endl;}