蓝书P244~P245
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 100000 + 24;
int Next[maxn], last, cur;
char s[maxn];
int main() {
while(~scanf("%s", s+1)) {
int len = strlen(s+1);
memset(Next, 0, sizeof(Next));
Next[0] = 0;
last = cur = 0;
for(int i = 1; i <= len; ++i) {
if(s[i] == '[') {
cur = 0;
}
else if(s[i] == ']') {
cur = last;
}
else {
Next[i] = Next[cur];
Next[cur] = i;
if(cur == last) {
last = i;
}
cur = i;
}
}
for(int i = Next[0]; i != 0; i = Next[i]) {
printf("%c", s[i]);
}
printf("\n");
}
}