贴一下我的code把233
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int x=0; x<n; x++) { string s; cin >> s; int i = 0, l = s.size(); stack<string> st; while(i < l) { if(s[i] == '(') { st.push("("); i++; } else if(s[i] == ')') { string ans = ""; while(!st.empty() && st.top() != "(") { ans.insert(0,st.top()); st.pop(); } st.pop(); st.push(ans); i++; } else if(s[i] >= '0' && s[i] <= '9') { int ans = 0; while(i < l && s[i] >= '0' && s[i] <= '9') { ans = ans * 10 + (s[i] - '0'); i++; } string ss = st.top(); st.pop(); string tmp; for(int i=0; i<ans; i++) tmp += ss; st.push(tmp); } else { string ss; ss.push_back(s[i]); st.push(ss); i++; } } string res; while(!st.empty()) { res.insert(0, st.top()); st.pop(); } cout << res <<endl; } return 0; }