백준 11729 c++
#include <iostream>
#include <cmath>
using namespace std;
int input(int lower, int upper);
void hanoi(int n, int from, int to, int by);
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
N = input(1, 20);
cout << ((int)pow(2, N) - 1) << "\n";
hanoi(N, 1, 3, 2);
return 0;
}
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
void hanoi(int n, int from, int to, int by)
{
if (n == 1)
{
cout << from << " " << to << "\n";
}
else
{
hanoi(n - 1, from, by, to);
cout << from << " " << to << "\n";
hanoi(n - 1, by, to, from);
}
return;
}