📄 hannoi.cpp
字号:
#include<iostream>
#include<fstream>
using namespace std;
void move(int n,char x,char y);
void hannoi(int n,char a,char b,char c);
ofstream out("out.txt");
void main()
{
int n;
cout<<"please input the hannoi's deepth:\n";
cin>>n;
out<<"The multuplate process as fllows:\n";
hannoi(n,'A','B','C');
cout<<"the result has input into the out text!\n";
}
void move(int n,char x,char y)
{
out<<"The "<<n<<"disk was removed from"<<x<<"to"<<y<<" : "<<x<<"-->"<<y<<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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -