- 分享
汉诺塔破解(不是原创)
- 2023-11-24 17:25:57 @
#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;
}
2 comments
-
经开一中2026届11班关泽瑞 LV 6 @ 2023-11-24 17:28:59
丑
-
2023-11-24 17:27:03@
汉诺塔破解版 #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