贴一下我的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; }
点赞 评论

相关推荐

02-05 08:49
已编辑
武汉大学 Web前端
野猪不是猪🐗:36k和36k之间亦有差距,ms的36k和pdd的36k不是一个概念
点赞 评论 收藏
分享
01-18 09:26
已编辑
门头沟学院 Java
王桑的大offer:建议中间件那块写熟悉即可,写掌握 面试包被拷打到昏厥
点赞 评论 收藏
分享

牛客热帖

更多
牛客网
牛客企业服务