Pagini recente » Borderou de evaluare (job #1701632) | Borderou de evaluare (job #317912) | Borderou de evaluare (job #487538) | Borderou de evaluare (job #981227) | Cod sursa (job #2872405)
#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 * 2 + cuv[i]);
if (Cauta(h1) == 0)
Add(h1);
}
pow = 1;
h1 = 0;
for (i = 0; i < len; i++)
{
h1 = (h1 * 2 + s[i]);
if (i)
pow = pow * 2;
}
sol += Cauta(h1);
for (i = len; s[i]; i++)
{
h1 = (h1 - s[i - len] * pow) * 2 + s[i];
sol += Cauta(h1);
}
fout << sol << "\n";
return 0;
}