Pagini recente » Cod sursa (job #988957) | Cod sursa (job #1049260) | Cod sursa (job #268600) | Cod sursa (job #1330319) | Cod sursa (job #2872384)
#include <bits/stdc++.h>
#define P 15029
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
char s[10000005];
char cuv[30];
vector <int> a[P];
void Add(int x)
{
int r = x % P;
a[r].push_back(x);
}
bool Cauta(int x)
{
int r = x % P;
for (auto w : a[r])
if (x == w)
return 1;
return 0;
}
int main()
{
int cod, h1, i, pow, len, sol = 0;
fin >> s;
while (fin >> cuv)
{
h1 = 0;
pow = 1;
len = strlen(cuv);
for (i = 0; cuv[i]; i++)
h1 = (h1 * 97 + cuv[i]) % P;
if (Cauta(h1) == 0)
Add(h1);
}
pow = 1;
h1 = 0;
for (i = 0; i < len; i++)
{
h1 = (h1 * 97 + s[i]) % P;
if (i)
pow = pow * 97 % P;
}
sol += Cauta(h1);
for (i = len; s[i]; i++)
{
h1 = ((h1 - s[i - len] * pow % P + P) * 97 + s[i]) % P;
sol += Cauta(h1);
}
fout << sol << "\n";
return 0;
}