提交时间:2023-10-05 09:45:47
运行 ID: 105069
#include<iostream> using namespace std; void hanoi(int num,char a,char b,char c) { if(num==1) { cout<<a<<"->"<<c<<endl; return; } else { hanoi(num-1,a,c,b); cout<<a<<"->"<<c<<endl; hanoi(num-1,b,a,c); } } int main() { int n; cin>>n; hanoi(n,'A','B','C'); return 0; }