Maintain a stack ... If the stack at the top of the string to be deleted will be completely deleted, it is good to judge the words ... KMP on the line.
1 /**************************************************************2 problem:39423 User:rausen4 language:c++5 result:accepted6 time:224 Ms7 memory:11548 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <cstring> A - using namespacestd; - Const intN = 1e6 +5; the - CharS1[n], s2[n], s[n]; - intNext[n], a[n], top; - + intMain () { - intI, J, Len; +Gets (S1 +1), gets (S2 +1); ALen = strlen (s2 +1); at for(i =2, j = next[1] =0; S2[i]; ++i) { - while(j && s2[i]! = s2[j +1]) J =Next[j]; - if(S2[i] = = S2[j +1]) ++J; -Next[i] =J; - } - for(i =1; S1[i]; ++i) { inj = A[top], s[++top] =S1[i]; - while(J && S2[j +1]! = S[top]) j =Next[j]; to if(S[top] = = S2[j +1]) ++J; +A[top] =J; - if(A[top] = = len) Top-=Len; the } *S[top +1] =' /'; $Puts (S +1);Panax Notoginseng return 0; -}View Code
(P.S. AC600 Memorial ~)
BZOJ3942 [Usaco2015 feb]censoring