https://www.luogu.org/problemnew/show/P1928
沙比提
读清题目
#include <bits/stdc++.h> using namespace std; const int N = 20010; int pre[N], hou[N]; string s; string ss; int main() { cin >> s; if(s.find(‘[‘) == -1) { cout << s; return 0; } for(int T = 1; T <= 10; T ++){ if(T != 1) s = ss; int len = s.length(), last; if(s.find(‘[‘) == -1) break; memset(hou, 0, sizeof(hou)); bool flag; for(int i = 0; i < len; i ++){ if(s[i] == ‘[‘) {last = i; flag = 1;} else if(s[i] == ‘]‘ && flag) {hou[last] = i; flag = 0;} } ss.clear(); for(int i = 0; i < len; i ++){ if(!hou[i]) {ss += s[i]; continue ;} int tot = 0, j; j = i + 1; while(s[j] >= ‘0‘ && s[j] <= ‘9‘){ tot = tot * 10 + s[j] - ‘0‘; j ++; } string s1; while(s[j] != ‘]‘) s1 += s[j ++]; for(int k = 1; k <= tot; k ++) ss += s1; i = hou[i]; } } cout << ss; return 0; }