Pagini recente » Cod sursa (job #1969012) | Cod sursa (job #984210) | Cod sursa (job #2518604) | Cod sursa (job #1802727) | Cod sursa (job #2872651)
#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 + 5];
int sol;
bool Cauta(int x)
{
int r = x % P;
for (auto w : a[r])
if (w == x)
return 1;
return 0;
}
void Add(int x)
{
int r = x % P;
a[r].push_back(x);
}
int main()
{
int i, h, pow = 1, len;
fin >> s;
while (fin >> cuv)
{
h = 0;
len = strlen(cuv);
for (i = 0; cuv[i]; i++)
h = (h * 2 + (cuv[i] - 'a' + 1));
if (Cauta(h) == 0)
Add(h);
}
h = 0;
for (i = 0; i < len; i++)
{
if (i)
pow *= 2;
h = (h * 2 + (s[i] - 'a' + 1));
}
sol = Cauta(h);
for (i = len; s[i]; i++)
{
h = (h - pow * (s[i - len] - 'a' + 1)) * 2 + (s[i] - 'a' + 1);
sol += Cauta(h);
}
fout << sol << "\n";
return 0;
}