#include<iostream>
#include<cstdio>
using namespace std;
int count;
void dfs(int stick,char a,char b,char c)
{
if(stick==1)
{
printf("第%d次 %c-->%c\n",++count,a,c);
return;
}
dfs(stick-1,a,c,b);
printf("第%d次 %c-->%c\n",++count,a,c);
dfs(stick-1,b,a,c);
}
int main()
{
int stick;
while(cin>>stick)
{
count=0;
dfs(stick,'A','B','C');
}
return 0;
}
经典的汉诺塔问题
最新推荐文章于 2024-07-22 11:04:13 发布