백준 1914 c++
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
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 if(n <= 20)
{
hanoi(n - 1, from, by, to);
cout << from << " " << to << "\n";
hanoi(n - 1, by, to, from);
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, point;
string total;
N = input(1, 100);
total = to_string(pow(2, N));
point = total.find('.');//'.'의 위치 인덱스
total = total.substr(0, point);//시작부터 '.'앞까지
total[total.length() - 1] -= 1; //total 마지막 위치 값을 -1
cout << total << "\n";
if (N <= 20)
{
hanoi(N, 1, 3, 2);
}
else
{
;
}
return 0;
}