#include<iostream>usingnamespace std;#include<vector>#include<string>classSolution{public:voidhans(int n, string A, string B, string C,int& steps ){if(n ==0)return;if(n ==1){
cout <<" move "<< n <<" from "<< A <<" to "<< C << endl;;
steps++;return;}hans(n -1, A, C, B, steps);//将A上面n-1个通过C移到B
cout <<" move "<< n <<" from "<< A <<" to "<< C << endl;//将A最后一个移到C
steps++;hans(n -1, B, A, C, steps);//将B上面n-1个通过空的A移到C}};intmain(){int steps =0;
Solution slt;
slt.hans(3,"A","B","C",steps);
cout << steps << endl;system("pause");return0;}