Mai intai trebuie sa te autentifici.
Cod sursa(job #99543)
Utilizator | Data | 11 noiembrie 2007 12:38:24 | |
---|---|---|---|
Problema | Abc2 | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Happy Coding 2007 | Marime | 0.88 kb |
#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]++;
}
return 0;
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;
}