백준
[11729] 하노이 탑 이동 순서
Jcoder
2018. 10. 29. 21:12
#include <iostream>using namespace std;void HanoiTowerMove(int num, int from, int by, int to){if (num == 0) // 이동할 원반의 수가 1개라면return;else{HanoiTowerMove(num - 1, from, to, by); // 3단계 중 1단계printf("%d %d\n", from, to); // 3단계 중 2단계HanoiTowerMove(num - 1, by, from, to); // 3단계 중 3단계}}int main(void){int n;cin >> n;cout << (1 << n) - 1 << "\n";HanoiTowerMove(n, 1, 2, 3);return 0;}