2015年4月9日 星期四

TIOJ 1355 河內之塔-蘿莉塔

#include <cstdio>
#include <cstdlib>
int step;
void ho(int n, int a, int b, int c){
    if(n == 1)
        printf("#%d : move the dish from #%d to #%d \n",step++, a ,c);
    
    else{
        ho(n-1, a, c, b);
        ho(1, a, b, c);
        ho(n-1, b, a, c);
    }
}

int main(){
    int n;
    scanf("%d",&n);
    step = 1;
    ho(n, 1, 2, 3);
}

沒有留言:

張貼留言