汉诺塔

#include <iostream>
using namespace std;
int main()
{
	void hanno(int ,char ,char,char);
	int n;
	cin>>n;
	hanno(n,'A','B','C');
	return 0;
}
void hanno(int n,char A,char B,char C)
{
	if(n==1)
		cout<<"Move disk "<<n<<" from "<<A<<" to "<<C<<endl;
	else 
	{
		hanno(n-1,A,C,B);
		cout<<"Move disk "<<n<<" from "<<A<<" to "<<C<<endl;
		hanno(n-1,B,A,C);
	}
}
汉诺塔讲解
posted @ 2017-06-11 15:54  衣带渐宽、为伊憔悴  阅读(105)  评论(0编辑  收藏  举报