[BOJ] 11729번 하노이 탑 이동 순서

yeham·2022년 11월 8일
0

백준

목록 보기
7/22

문제

하노이 탑 이동 순서

코드

#include <iostream>
#include <cmath>

using namespace std;

void ft_hanoi(int a, int b, int n)
{
	int c;
	if (n == 1)
	{
		cout << a << ' ' << b << '\n';
		return ;
	}
    c = 6 - a - b;
	ft_hanoi(a, c, n - 1);
		cout << a << ' ' << b << '\n';
	ft_hanoi(c, b, n - 1);
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n;
    int count;
	cin >> n;
	count = pow(2, n) - 1;
	cout << count << '\n';
	ft_hanoi(1, 3, n);
	return (0);
}
profile
정통과 / 정처기 & 정통기 / 42seoul 7기 Cardet / 임베디드 SW 개발자

0개의 댓글