Topic Links:
https://cn.vjudge.net/problem/UVA-11988
1 /*2 The problem is that a piece of text after a certain rule processing output, the rule is [the home key, indicating that the cursor jumps to the beginning of the line,] means the end key, indicating that the cursor jumps to the end3 4 Thinking of solving problems5 It can be found that [] can be nested, using pure simulation is more complex, similar to the next array in the KMP, record the next character position of each character, and finally6 output can be. 7 */ 8#include <iostream>9#include <cstdio>Ten#include <cstring> One#include <list> A Const intmaxn=101000; - using namespacestd; - the CharSTR[MAXN]; - intNEX[MAXN]; - intMain () - { + intI,len,cur,las; - //freopen ("E:\\testin.txt", "R", stdin); + while(SCANF ("%s", str+1) !=EOF) { ALen=strlen (str+1); atcur=las=0; -nex[0]=0; - for(i=1; i<=len;i++){ - if(Str[i] = ='[') -Cur=0; - Else if(Str[i] = =']') inCur=Las; - Else{ tonex[i]=Nex[cur]; +nex[cur]=i; - if(cur = = las) Las =i; theCur =i; * } $ }Panax Notoginseng - for(i=nex[0];i! =0; i=Nex[i]) { theprintf"%c", Str[i]); + } APuts""); the } + return 0; -}
UVa 11988 broken Keyboard (array analog list)