U E D R , A S I H C RSS

하노이탑/윤성복

~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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:29
Processing time 0.0067 sec