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
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<deque>
#include<stack>
using namespace std;
#define ull unsigned long long
const int maxn=5000005;
ull h[maxn],hash[maxn],base=123;
char t1[maxn],t2[maxn];
struct node
{
char t;
ull x;
}c[maxn];
int main()
{
h[0]=1;
for(int i=1;i<maxn;i++)h[i]=h[i-1]*base;
while(~scanf("%s%s",t1+1,t2+1))
{
int L1=strlen(t1+1),L2=strlen(t2+1);
//printf("%d %d\n",L1,L2);
if(L2<L1)printf("%s\n",t2+1);
else
{
ull tt=0;
for(int i=1;i<=L1;i++)tt=tt*base+t1[i];
int tol=1;
for(int i=1;i<=L2;i++)
{
node e;e.t=t2[i];
if(tol==1)
{
e.x=t2[i];c[tol++]=e;
}
else
{
e.x=c[tol-1].x*base+t2[i];
c[tol++]=e;
}
if(tol>L1)
{
if(c[tol-1].x-h[L1]*c[tol-L1-1].x==tt)
{
tol-=L1;
}
}
}
for(int i=1;i<tol;i++)printf("%c",c[i].t);
printf("\n");
}
}
return 0;
}