몇시간 종이에 적으면서 고민하다가 결국 풀었음

문제푸는게 참 성취감이 있네 ㄷㄷ


void hanoiTower(int disks, int presentPlace, int temporaryPlace, int targetPlace) {

if (disks == 2) {

cout << presentPlace << " → " << temporaryPlace << endl;


cout << presentPlace << " → " << targetPlace << endl;


cout << temporaryPlace << " → " << targetPlace << endl;

}

if (disks > 2) {

hanoiTower(disks - 1, presentPlace, targetPlace, temporaryPlace);


cout << presentPlace << " → " << targetPlace << endl;


hanoiTower(disks - 1, temporaryPlace, presentPlace, targetPlace);

}

}