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.0072 sec