1. 程式人生 > >Broken Keyboard(a.k.a.Beiju Text),UVa 11988

Broken Keyboard(a.k.a.Beiju Text),UVa 11988

#include<iostream>
#include<stack>
#include<string>
using namespace std;

int last,cur;
char s[100005];

int main(){
	int next[100005];
	while(cin>>s+1){
		int n=strlen(s+1);
		last=cur=0;
		next[0]=0;

		for(int i=1;i<=n;i++){
			char ch=s[i];
			if(ch=='[')cur=0;
			else if(ch==']')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])
			cout<<s[i];
		cout<<endl;
	}
}