Article directory
Question 251.2022 Winter Ladder Training - 7-14 Tower of Hanoi Problem (10 points)
1. The topic
2. Problem solving
#include <bits/stdc++.h>
using namespace std;
void move(char src,char des)
{
printf("%c-->%c\n",src,des);
}
void hanoi(int n,char src,char med,char des)
{
if(n==1)
{
move(src,des);
return;
}
hanoi(n-1,src,des,med);
move(src,des);
hanoi(n-1,med,src,des);
}
int main()
{
int n;
cin>>n;
hanoi(n,'A','B','C');
}