Happy_Birthday_to_Tsinghua_University
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 100005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) char str[N]; int next[N]; int main() { int i,j,cur,last; while(gets(str+1)) { int len = strlen(str+1); cur = last = 0; next[0] = 0; for(i = 1; i<=len; i++) { if(str[i]=='[') cur = 0; else if(str[i]==']') cur = last; else { next[i] = next[cur]; next[cur] = i; if(last == cur) last = i; cur = i; } } for(i = next[0]; i; i = next[i]) printf("%c",str[i]); puts(""); } return 0; }