Pagini recente » Cod sursa (job #2627187) | Cod sursa (job #1088740) | Cod sursa (job #2824410) | Cod sursa (job #798127) | Cod sursa (job #1481820)
#include <stdio.h>
#include <cstring>
#include <vector>
#define lmax 10000010
#define hmod 666013
#define mod 99991
#define p 257
using namespace std;
int n,i,m,p1,sol=0;
unsigned int curenthash;
char s[lmax],ss[30];
vector <int> uhash[mod+10];
bool inhash(int x)
{
int y=x%mod;
for (unsigned int i=0;i<uhash[y].size();i++)
if (uhash[y][i]==x) return true;
return false;
}
int main() {
freopen("abc2.in","r",stdin);
freopen("abc2.out","w",stdout);
gets(s+1); n=strlen(s+1);
while (gets(ss+1)>0) {
m=strlen(ss+1); curenthash=0;
for (i=1;i<=m;i++) curenthash=(curenthash*p+ss[i])%hmod;
if (!inhash(curenthash)) uhash[curenthash%mod].push_back(curenthash);
}
curenthash=0; p1=1;
for (i=1;i<=m;i++) {
curenthash=(curenthash*p+s[i])%hmod;
if (i>1) p1=(p1*p)%hmod;
}
sol=sol+inhash(curenthash);
for (i=m+1;i<=n;i++) {
curenthash=(((curenthash-(s[i-m]*p1)%hmod)+hmod)*p+s[i])%hmod;
sol=sol+inhash(curenthash);
}
printf("%d",sol);
return 0;
}