Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define X first
- #define Y second
- #define ll long long
- #define pii pair<int, int>
- #define is insert
- #define er erase
- using namespace std;
- int n, k;
- void Hanoi(int n, int a, int b, int c){
- if(n == 0){
- return;
- }
- if(n == 1){
- cout << n << " " << a << " " << c << endl;
- return;
- }
- else{
- Hanoi(n - 1, a, c, b);
- cout << n << " " << a << " " << c << endl;
- Hanoi(n - 1, b, a, c);
- }
- }
- int main(){
- #ifdef DEBUG
- freopen("input.txt", "r", stdin);
- #endif // DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- k = 0;
- for(int i = n; i >= 1; --i){
- if(i % 2 == 1){
- Hanoi(i - 1, 1, 2, 3);
- cout << i << ' ' << 1 << ' ' << 2 << endl;
- Hanoi(i - 1, 3, 2, 1);
- }
- else{
- Hanoi(i - 1, 1, 3, 2);
- cout << i << ' ' << 1 << ' ' << 3 << endl;
- Hanoi(i - 1, 2, 3, 1);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement