Pagini recente » Cod sursa (job #1548844) | Cod sursa (job #1300340) | Cod sursa (job #1990386) | Cod sursa (job #444364) | Cod sursa (job #99540)
Cod sursa(job #99540)
#include <stdio.h>
#include <string.h>
#define lmax 10000005
#define wmax 25
#define usi unsigned short int
#define hmax 100000
#define baza 3
char s[lmax], s1[wmax];
int tot, i, hs, l, crt = 0, tbaza;
usi a[hmax];
int main()
{
freopen("abc2.in", "r", stdin);
freopen("abc2.out", "w", stdout);
scanf("%s\n", s);
while(!feof(stdin))
{
scanf("%s\n", s1);
hs = 0; l = strlen(s1);
for(i = 0; i < (int)strlen(s1); i++) {
hs = hs * baza + (s1[i] - 'a');
while(hs >= hmax) hs -= hmax;
}
a[hs]++;
}
hs = 0; tbaza = 1;
for(i = 0; i < l - 1; i++)
{
crt++; tbaza *= baza;
hs = hs * baza + (s[i] - 'a');
while(hs >= hmax) hs -= hmax;
}
for(i = l - 1; i < (int)strlen(s); i++)
{
hs = hs * baza + (s[i] - 'a');
while(hs >= hmax) hs -= hmax;
if(a[hs]) tot++;
if(s[i - l] - 'a' != 0) hs /= (s[i - l] - 'a') * tbaza;
}
printf("%d\n", tot);
return 0;
}