#include<stdio.h>
void moveto(int n,char from,char to)
{
int i=1;
printf("第%d步将盘子%d从%c----->%c\n",i++,n,from,to);
}
void haoni(int n,char from,char depend_on,char to)
{
if(n==1)
{
moveto(1,from,to);
}
else
{
haoni(n-1,from,to,depend_on);
moveto(n,from,to);
haoni(n-1,depend_on,from,to);
}
}
int main()
{
int n;
printf("请输入盘子的个数:");
scanf("%d",&n);
haoni(n,'A','B','C');
return 0;
}
void moveto(int n,char from,char to)
{
int i=1;
printf("第%d步将盘子%d从%c----->%c\n",i++,n,from,to);
}
void haoni(int n,char from,char depend_on,char to)
{
if(n==1)
{
moveto(1,from,to);
}
else
{
haoni(n-1,from,to,depend_on);
moveto(n,from,to);
haoni(n-1,depend_on,from,to);
}
}
int main()
{
int n;
printf("请输入盘子的个数:");
scanf("%d",&n);
haoni(n,'A','B','C');
return 0;
}