Pagini recente » Cod sursa (job #626134) | Cod sursa (job #2984934) | Cod sursa (job #2597432) | Cod sursa (job #624034) | Cod sursa (job #1481834)
#include <stdio.h>
#include <cstring>
#include <vector>
#include <map>
#define lmax 10000010
#define mod1 666013
#define mod2 787613
#define p 257
using namespace std;
int n,i,m,p1,p2,sol=0,curenthash1,curenthash2;
char s[lmax],ss[30];
map <int,int> mp;
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); curenthash1=0; curenthash2=0;
for (i=1;i<=m;i++)
curenthash1=(curenthash1*p+ss[i])%mod1,
curenthash2=(curenthash2*p+ss[i])%mod2;
mp[curenthash1]=curenthash2;
}
curenthash1=0; curenthash2=0; p1=1; p2=1;
for (i=1;i<=m;i++) {
curenthash1=(curenthash1*p+s[i])%mod1;
curenthash2=(curenthash2*p+s[i])%mod2;
if (i>1) p1=(p1*p)%mod1,p2=(p2*p)%mod2;
}
if (mp[curenthash1]==curenthash2) sol++;
for (i=m+1;i<=n;i++) {
curenthash1=(((curenthash1-(s[i-m]*p1)%mod1)+mod1)*p+s[i])%mod1;
curenthash2=(((curenthash2-(s[i-m]*p2)%mod2)+mod2)*p+s[i])%mod2;
if (mp[curenthash1]==curenthash2) sol++;
}
printf("%d",sol);
return 0;
}