UVa-11988 - Broken Keyboard (a.k.a. Beiju Text)
原来数组可以代替指针,涨姿势
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int maxx=100010; 6 char a[maxx]; 7 int next[maxx],cur,last; 8 int main() 9 { 10 while(~scanf("%s",a+1)) 11 { 12 int len=strlen(a+1); 13 next[0]=0; 14 cur=last=0; 15 for(int i=1;i<=len;i++) 16 { 17 if(a[i]=='[') cur=0; 18 else if(a[i]==']') cur=last; 19 else 20 { 21 next[i]=next[cur]; 22 next[cur]=i; 23 if(cur==last) last=i; 24 cur=i; 25 } 26 } 27 for(int i=next[0];i;i=next[i]) 28 printf("%c",a[i]); 29 printf("\n"); 30 } 31 }