- 分享
汉诺塔代码,谁会解释
- 2023-11-24 17:30:20 @
#include <bits/stdc++.h> using namespace std; int cnt; 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); } cnt ++ ; }
int main() { int a; cin >> a;
move(a, 'A', 'B', 'C');
cout << "次数:" << cnt << endl;
return 0;
}
1 comments
-
zhiyinnitaimei LV 7 @ 2023-11-24 17:34:29
你就只会Ctrl c + Ctrl v是吧
- 1