ハノイの塔

#geshi(cpp){{

#include <iostream>

#include <string>

#define FROM "A"

#define TO "B"

#define WORK "C"

using namespace std; unsigned int counter;

void solve(int x, string from, string to, string work){

	if(x == 1){
		cout << ++counter << ": " << from << " to " << to << endl;
	}else{
		solve(x-1, from, work, to);
		cout << ++counter << ": " << from << " to " << to << endl;
		solve(x-1, work, to, from);
	}

}

int main() {

	int x;
	// Input the circle count
	cout << "Input x > ";
	cin >> x;
	counter = 0;
	solve(x, FROM, TO, WORK);
	return 0;

}

}}


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS