#include<iostream.h>
void move(char source,char target)
{
 cout<<source<<"==>"<<target<<endl;
}
void hanoi(int n,char source,char temp,char target)
{
 if(n==1)
  move(source,target);
 else
 {
  hanoi(n-1,source,target,temp);
  move(source,target);
  hanoi(n-1,temp,source,target);
 }
}
void main()
{
 int n;
 while(1)
 { 
 cout<<"Input the number of disks:"<<endl;
 cin>>n;
 cout<<"The step to moving "<<n<<" disks:"<<endl;
 hanoi(n,'A','B','C');}
}
posted on 2011-04-28 20:37  pcoda  阅读(136)  评论(0编辑  收藏  举报