// sf1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
using namespace std;
void hanno(int n,char A,char B, char C)
{
if(n==1)
{cout<<"move sheet "<<n<<"from "<<A<<"to "<<C<<endl;}
else
{
hanno(n-1,A,C,B);
cout<<"move sheet "<<n<<"from"<<A<<"to"<<C<<endl;
hanno(n-1,B,A,C);
}
}
int main()
{
int n;
cout<<"please input the sheet number:"<<endl;
cin>>n;
hanno(n,'A','B','C');
return 0;
}
(1)汉诺塔
最新推荐文章于 2019-12-02 23:19:54 发布