//10层汉诺塔递归解法,过程输出到文件
#include <fstream>
#include <iostream>
using namespace std;
ofstream fout("out.txt");
void Move(int n, char i, char j)
{
fout<< "把" << n << "号从" << i << "移动到" << j <<endl;
}
void Hannoi(int n, char a, char b, char c)
{
if (n == 1)
{
Move(1, a, c);
}
else
{
Hannoi(n - 1, a, c, b);
Move(n, a, c);
Hannoi(n - 1, b, a, c);
}
}
int main()
{
fout<<"以下是10层汉诺塔的解法:"<<endl;
Hannoi(10, 'a', 'b', 'c');
fout.close();
cout<<"输出结果完毕。"<<endl;
return 0;
}