Advertisement
achulkov2

Untitled

Feb 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void hanoi(int x, int y, int n)
  7. {
  8. if (n > 1)
  9. hanoi(x, 6 - x - y, n - 1);
  10. cout << n << ' ' << x << ' ' << y << endl;
  11. if (n > 1)
  12. hanoi(6 - x - y, y, n - 1);
  13. }
  14.  
  15. int main()
  16. {
  17. int n;
  18. cin >> n;
  19. if (n % 2 == 1)
  20. hanoi(1, 2, n);
  21. else
  22. hanoi(1, 3, n);
  23. for (int i = n - 1; i >= 1; i--)
  24. {
  25. if (i % 2 == 0)
  26. {
  27. hanoi(2, 3, i);
  28. }
  29. else
  30. {
  31. hanoi(3, 2, i);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement