题解
2025-03-23 21:55:21
发布于:江苏
0阅读
0回复
0点赞
#include<iostream>
using namespace std;
void hanoi(int n,char from,char to,char aux){
if(n==1){
cout<<from<<" --"<<n<<"--> "<<to<<endl;
return;
}
hanoi(n-1,from,aux,to);
cout<<from<<" --"<<n<<"--> "<<to<<endl;
hanoi(n-1,aux,to,from);
}
int main(){
int n;
cin>>n;
hanoi(n,'A','C','B');
}
这里空空如也
有帮助,赞一个