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
// 题意:第一行一个敏感词,然后一行文本,操作如下,删除敏感词,然后如果又新组成敏感词, 重复删掉,直到没有敏感词
//如果用KMP和模拟链表的话,就是如果匹配成功了,用链表删除后,再回退lent长度继续匹配,有点麻烦,貌似还可以hash做
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string.h>
using namespace std;
const int MX=; int lens,lent;
char T[MX];
char S[MX];
int l[MX];
int r[MX];
int fail[MX]; void getfail()
{
int i,j;
i=,j=;
fail[]=;
while(i<lent)
{
if (j==||T[i]==T[j])
{
i++,j++;
fail[i]=j;
}
else j = fail[j];
}
} void kmp()
{
int i=;
int j=;
while(i<=lens&&j<=lent)
{
if (j==||S[i]==T[j])
{
i=r[i];
j++;
}
else j = fail[j]; if (j>lent)
{
int num=;
int pos=i;
while (num<lent)
{
pos = l[pos];
num++;
}
r [ l[ pos ] ] = i;
l [ i ] = l[ pos ]; num=;
pos=i;
while (num<lent)
{
if (l[pos]==) break;
pos = l[pos];
num++;
}
j=;
i = pos;
}
}
} int main()
{
while(scanf("%s",T+)!=EOF)
{
scanf("%s",S+);
lens = strlen(&S[]);
lent = strlen(&T[]); getfail(); for (int i=;i<=lens+;i++)
{
l[i] = i-;
r[i] = i+;
} kmp();
for (int i = r[];S[i];i = r[i])
{
printf("%c",S[i]);
}
printf("\n");
}
return ;
}