经典汉诺塔

#include"iostream"
using namespace std;

void move(int n,char a,char b,char c){
    if(n == 1){
        cout<<n<<ends<<a<<" to "<<c<<endl;
    }
    else{
        move(n - 1,a,c,b);
        cout<<n<<ends<<a<<" to "<<c<<endl;
        move(n - 1,b,a,c);
    }
}

int main(){
    move(3,'A','B','C');
    return 0;
}

 

posted @ 2018-05-12 12:53  oleolema  阅读(113)  评论(0编辑  收藏  举报