#include<iostream> using namespace std; void move(char a,char c){ cout<<a<<"-->"<<c<<endl; } int fun1(int n,char A,char B,char C){//将n个盘子借助B从A盘移到C int steps=0; if(n==1) move(A,C);//将最后一个盘子从A移到C else{ fun1(n-1,A,C,B);//将n-1个盘子借助C从A盘移到B盘 steps++; move(A,C);//将最后一个盘子从 A移到C fun1(n-1,B,A,C);//将n-1个盘子借助A盘从B盘移到C盘 } } int main(){ int m; cout<<"Enter the number of diske:"; cin>>m; cout<<"The steps to moving"<<m<<"diskes:"<<endl; fun1(m,'A','B','C'); system("pause"); return 0; }