// 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)汉诺塔
最新推荐文章于 2025-09-24 21:44:51 发布
本文介绍了一个使用C++实现的汉诺塔问题解决方案。通过递归算法演示了如何将不同数量的盘子从一个柱子移动到另一个柱子的过程,并详细展示了具体的代码实现。
1279

被折叠的 条评论
为什么被折叠?



