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