- 题解
汉诺塔
- 2023-11-24 19:12:45 @
using namespace std;
int s;
void move(int n ,char x,char y ,char z)
{
if(n==1)
cout << x << "->" << z << endl;
else
{
move(n-1,x,z,y);
cout << x << "->" << z << endl;
move(n-1,y,x,z);
}
s ++;
}
int main()
{
int a;
cin >> a;
move(a,'X' ,'Y' ,'Z');
cout << "次数:" << s << endl;
return 0;
}
1 comments
-
经开一中2026届11班关泽瑞 LV 6 @ 2023-11-24 19:18:39
额
- 1