Pagini recente » Cod sursa (job #1205737) | Cod sursa (job #46231) | Cod sursa (job #9525) | Cod sursa (job #231594) | Cod sursa (job #101708)
Cod sursa(job #101708)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define S ((1<<23)-1)
int V[S+10][2], Nr;
char ss[10000002], ss2[50002];
int main()
{
int i, j, l, n, nv = 0;
long long hash, hash2, x, y;
srand(time(0));
freopen("abc2.in", "r", stdin);
gets(ss);
n = strlen(ss);
scanf(" ");
gets(ss2);
l = strlen(ss2);
n = n-l;
for (i = 0; i <= n; i++)
{
hash = hash2 = 0;
for (j = 0; j < l; j++)
{
x = (hash<<13);
y = (hash2<<23);
hash = (hash+x+ss[i+j])&S;
hash2 = (hash2+y+ss[i+j])&S;
}
V[nv][0] = hash; V[nv++][1] = hash2;
}
hash = y;
for (j = 0; j < l; j++)
{
x = (hash<<13);
hash = (hash+ss2[j])&S;
}
Nr += V[hash][0];
V[hash][0] = 0;
while (scanf(" %s", ss2)!=EOF)
{
hash = y;
for (j = 0; j < l; j++)
{
x = (hash*y);
hash = (hash+ss2[j]+x)&S;
}
Nr += V[hash][0];
V[hash][0] = 0;
}
freopen("abc2.out", "w", stdout);
printf("%d\n", Nr);
return 0;
}