hanoi.cpp
来自「采用c++语言」· C++ 代码 · 共 27 行
CPP
27 行
#include<iostream.h>
void Move(char getone,char putone)
{
cout<<getone<<"->"<<putone<<endl;
}
void Hanoi(int n,char one,char two,char three)
{
if(n==1)Move(one,three);
else
{
Hanoi(n-1,one,three,two);
Move(one,three);
Hanoi(n-1,two,three,one);
}
}
void main()
{
int n;
cout<<"Enter the number of plate:"<<endl;
cin>>n;
cout<<"the steps of moving"<<n<<"plates:"<<endl;
Hanoi(n,'A','B','C');
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?