xt4-9.cpp
来自「谭浩强C程序设计习题答案」· C++ 代码 · 共 26 行
CPP
26 行
#include <iostream>
using namespace std;
int main()
{void hanoi(int n,char one,char two,char three);
int m;
cout<<"input the number of diskes:";
cin>>m;
cout<<"The steps of moving "<<m<<" disks:"<<endl;
hanoi(m,'A','B','C');
return 0;
}
void hanoi(int n,char one,char two,char three)
//将n个盘从one座借助two座,移到three座
{void move(char x,char y);
if(n==1) move(one,three);
else
{hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char x,char y)
{cout<<x<<"-->"<<y<<endl;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?