#include <iostream> #include <string> using namespace std; string helper(string& s, int& index) {     string res, tmp;     int x = 0;     while(index < s.size()) {         if(s[index] == '('){ #遇到左括号递归开始             index++;             res += helper(s,index);         }else if(s[index] == ')') { #遇到右括号计算后面的数字,算完之后return             index++;             while(s[index] >= '0' && s[index] <= '9') {                 x = x*10+(s[index++]-'0');             }             tmp = res;             while(--x)                 res += tmp;             return res;         }else if(s[index] >= '0' && s[index] <= '9') {#直接遇到数字说明是单个字母的重复             x = 0;             while(s[index] >= '0' && s[index] <= '9') {                 x = x*10+(s[index++]-'0');             }             while(--x)                 res += res.back();         }         else{#其它字母直接加             res += s[index++];         }     }     return res; } int main() {     int n = 0,index = 0;     string s;     getline(cin,s);     n = stoi(s);     for(int i = 0; i < n; i++) {         getline(cin,s);         index = 0;         string res = helper(s,index);         cout << res <<endl;     }     return 0; } 来个C++版的
点赞 评论

相关推荐

点赞 评论 收藏
分享
不吃牛肉的选手在刷面试经:首先,你数过吗?其次,他知道吗?最后,你说了他信吗?
点赞 评论 收藏
分享
牛客网
牛客企业服务