题解
2023-07-07 11:37:16
发布于:上海
78阅读
0回复
0点赞
#include <iostream>
using namespace std;
int count =0;
void hanno(int n, char a, char b, char c){
if(n==1){
printf("%c -> %c\n", a, c);
count++;
}else{
hanno(n-1, a, c, b);
printf("%c -> %c\n", a, c);
count++;
hanno(n-1, b, a, c);
}
}
int main(){
int n;
scanf("%d", &n);
hanno(n, 'A', 'B', 'C');
return 0;
}
这里空空如也
有帮助,赞一个