标签:
汉诺塔问题II
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1556 Solved: 720
2
a->b a->c b->c
三根柱子分别标为a b c
1 #include<stdio.h> 2 void hanoi (int n , char a , char b , char c) 3 { 4 if (n == 1) { 5 printf ("%c->%c\n" , a , c ) ; 6 } 7 else { 8 hanoi (n - 1 , a , c , b) ; 9 printf ("%c->%c\n" , a , c) ; 10 hanoi (n - 1 , b , a , c ) ; 11 } 12 } 13 14 int main () 15 { 16 int n ; 17 while (~ scanf ("%d" , &n) ) { 18 hanoi (n , ‘a‘ , ‘b‘ , ‘c‘) ; 19 } 20 return 0 ; 21 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4391677.html