5.6打卡

#include <bits/stdc++.h>
using namespace std;
void move(char src,char dest){
    cout<<src<<"-->"<<dest<<endl;
}
void hanoi(int n,char src,char medium,char dest)
{
    if(n==1)
    move(src,dest);
    else{
        hanoi(n-1,src,dest,medium);
        move(src,dest);
        hanoi(n-1,medium,src,dest);
    }
}
int main()
{
    int m;
    cout<<"enter the number of disks: ";
    cin>>m;
    cout<<"the steps to move "<<m<<"disks: "<<endl;
    hanoi(m,'A','B','C');
    return 0;
 } 

 

posted @ 2023-05-06 16:09  记得关月亮  阅读(7)  评论(0编辑  收藏  举报