http://fastvj.rainng.com/problem/SCU-4438
题意:一个文本串和模式串,如果文本串中出现了模式串直接删除,然后拼接成一个新串,继续删除。求最后处理过的字符串。
做法:先对模式串哈希,在对文本串逐一哈希,出现了,就立刻删除,然后继续哈希。
这倒题做法也很多,各大匹配算法都可以解决
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=10007;
const int N=1000010;
ull hash1[N*5],p[N*5];
char txt[N*5],str[N*5];
char st[N*5];
int main()
{
p[0]=1;
for(int i=1;i<N*5;i++) p[i]=p[i-1]*131;
while(~scanf("%s%s",str,txt))
{
int head,tail;
head=tail=0;
int len1=strlen(str);
int len2=strlen(txt);
ull tmp=str[0];
for(int i=1;i<len1;i++)
tmp=tmp*131+str[i];
hash1[0]=0;
int po=0;
for(int i=0;i<len2;i++)
{
st[tail++]=txt[i];
po++;
hash1[po]=hash1[po-1]*131+txt[i];
if(po<len1) continue;
ull tt=hash1[po]-hash1[po-len1]*p[len1];
if(tt==tmp)
{
int cnt=0;
while(cnt<len1){
tail--;
cnt++;
po--;
}
}
}
for(int i=0;i<tail;i++) printf("%c",st[i]);
printf("\n");
}
return 0;
}