SCU - 4438 (KMP)
Censor
frog is now a editor to censor so-called sensitive words (敏感词).
She has a long text pp. Her job is relatively simple – just to find the first occurence of sensitive word ww and remove it.
frog repeats over and over again. Help her do the tedious work.
Input
The input consists of multiple tests. For each test:
The first line contains 11 string ww. The second line contains 11 string pp.
(1≤length of w,p≤5⋅1061≤length of w,p≤5⋅106, w,pw,p consists of only lowercase letter)
Output
For each test, write 11 string which denotes the censored text.
Sample Input
abc
aaabcbc
b
bbb
abc
ab
Sample Output
a
ab
题意:
一个模板串tt,一个文本串ss,我们从文本穿ss中删除模板串tt,重复这一过程,直至文本串中不包含模板串 。输出最后的文本串。
思路:
前置知识:KMP
i i i 指针指文本串将要匹配的位置,j 指针指模式串将要匹配的位置
kmp用来文本串与模板串匹配,如果匹配成功怎么办? i i i指针回退?不,我们可以维护另一个数组,作为匹配过程中的数组;每次文本串的 i i i 指针往后移动时,就将新的字符加入一个像栈一样的数组;如果当前是完全匹配模板串 t t tt