汉诺塔

汉诺塔的移动

#include <iostream>
#include <cstdio>
using namespace std;
void mov(int n,char f,char t)
{
    printf("Move disk %d from %c to %c\n",n,f,t);
}
void Han(int n, char A, char B, char C)
{
    if(n == 1)
    {
        mov(n, A, C);
        return ;
    }
    Han(n - 1, A, C, B);
    mov(n, A, C);
    Han(n - 1, B, A, C);
}
int main()
{
    int n;
    cin>>n;
    Han(n,'A','B','C');
    return 0;
}

 

posted @ 2016-04-11 17:15  byonlym  阅读(128)  评论(0编辑  收藏  举报