提交时间:2025-07-17 09:22:13
运行 ID: 333928
#include<bits/stdc++.h using namespace std; int h(int n, char s, char d, char t) { int s1 = 0; if (n == 1) { cout << s << "->" << d << endl; return 1; } s1 += hanoi(n-1, s, t, d); cout << s << "->" << d << endl; s1++; s1 += hanoi(n-1, t, d, s); return s1; } int main() { int n; cin >> n; for(int i=1;i<=n;i++){ cout<<i<<":"; cout <<h(n, 'a', 'c', 'b'); } return 0; }