fork(1) download
  1. #include<stdio.h>
  2.  
  3. #include<math.h>
  4.  
  5. void hanoi(int n, char from, char tmp, char to) {
  6.  
  7. if (n == 1) {
  8.  
  9. printf("%c %c\n", from, to);
  10.  
  11. }
  12.  
  13. else {
  14.  
  15. hanoi(n - 1, from, to, tmp);
  16.  
  17. printf("%c %c\n",from, to);
  18.  
  19. hanoi(n - 1, tmp, from, to);
  20.  
  21. }
  22.  
  23. }
  24.  
  25. int main() {
  26.  
  27. int n;
  28.  
  29. int k;
  30.  
  31. scanf("%d", &n);
  32.  
  33. k = pow(2,n) - 1;
  34.  
  35. printf("%d", k);
  36.  
  37. hanoi(n, '1', '2', '3');
  38. return 0;
  39. }
Success #stdin #stdout 0s 4340KB
stdin
3
stdout
71 3
1 2
3 2
1 3
2 1
2 3
1 3