求助
查看原帖
求助
1048673
Tutu2010楼主2025/7/27 10:11
#include<iostream>
using namespace std;
static int count=1;
void move(char src,char dest) {
	count++;
}
void hanoi(int n,char src,char medium,char dest) {
	if(n==1) move(src,dest);
	else {
		hanoi(n-1,src,dest,medium);
		move(src,dest);
		hanoi(n-1,medium,src,dest);
	}
}
int main() {
	int m;
	cin>>m;
	hanoi(m,'A','B','C');
	cout<<count-1;
	return 0;
}
2025/7/27 10:11
加载中...