Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. #define mp make_pair
  4. #define X first
  5. #define Y second
  6. #define ll long long
  7. #define pii pair<int, int>
  8. #define is insert
  9. #define er erase
  10. using namespace std;
  11.  
  12. int n, k;
  13.  
  14. void Hanoi(int n, int a, int b, int c){
  15. if(n == 0){
  16. return;
  17. }
  18. if(n == 1){
  19. cout << n << " " << a << " " << c << endl;
  20. return;
  21. }
  22. else{
  23. Hanoi(n - 1, a, c, b);
  24. cout << n << " " << a << " " << c << endl;
  25. Hanoi(n - 1, b, a, c);
  26. }
  27. }
  28.  
  29. int main(){
  30. #ifdef DEBUG
  31. freopen("input.txt", "r", stdin);
  32. #endif // DEBUG
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. cout.tie(0);
  36. cin >> n;
  37. k = 0;
  38. for(int i = n; i >= 1; --i){
  39. if(i % 2 == 1){
  40. Hanoi(i - 1, 1, 2, 3);
  41. cout << i << ' ' << 1 << ' ' << 2 << endl;
  42. Hanoi(i - 1, 3, 2, 1);
  43. }
  44. else{
  45. Hanoi(i - 1, 1, 3, 2);
  46. cout << i << ' ' << 1 << ' ' << 3 << endl;
  47. Hanoi(i - 1, 2, 3, 1);
  48. }
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement