#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void hannuota(int &res, int shikuai, string a, string b, string c)
{
if (shikuai == 1)
{
res++;
cout << "第" << res << "步:";
cout << "把" << shikuai << "从" << a << "移到" << c << endl;
return;
}
hannuota(res, shikuai - 1, a, c, b);
res++;
cout << "第" << res << "步:"
<< "把" << shikuai << "从" << a << "移到" << c << endl;
hannuota(res, shikuai - 1, b, a, c);
}
int main()
{
//汉诺塔
int shikuai = 2;
int res = 0;
hannuota(res, shikuai, "A柱", "B柱", "C柱");
return 0;
}
C++汉诺塔
最新推荐文章于 2024-04-10 21:21:31 发布