~cpp
#include <iostream>
using namespace std;
int Mcount = 0; //동 변
int hanoi(int disk,int start, int other, int finish){
Mcount++; // 마 1
// 마막 디 1 start finish
if(disk == 1)
cout << start << " " << finish << endl;
// 디 1 면 마막
else
{
hanoi(disk-1,start,finish,other); // 뺀 들 other 는
cout << start << " " << finish << endl;
hanoi(disk-1,other,start,finish); // other 는 finish 는
}
return Mcount;
}
void main(){
int disk,MoveCount;
cout << "디 : ";
cin >> disk;
MoveCount = hanoi(disk,1,2,3);
cout << endl << " 동" << MoveCount << endl;
}