#include<stdio.h>
int count = 0;
void move(char a, char b, int n)
{
count++;
printf("%2d-(%2d):%c==>%c\n",count, n, a, b);
}
void HanoiTower(char a, char c, char b, int n)
{
if (n == 1)
{
move(a ,b, n);
}
else
{
//将n-1个圆盘从A柱借助于C柱移动到B柱上
HanoiTower(a,b,c, n - 1);
//将A柱子最后一个圆盘移动到C柱上
move(a,b,n);
//将n-1个圆盘从B柱借助于A柱移动到C柱上
HanoiTower(c, a, b, n - 1);
}
}
int main()
{
int n = 0;
printf("Please enter the number of discs:");
scanf("%d", &n);
//将n个圆盘从A柱借助于B柱移动到C柱上
HanoiTower('a','c','b', n);
printf("\tTotal:%d\n", count);
return 0;
}