Pagini recente » Cod sursa (job #368907) | Cod sursa (job #254523) | Cod sursa (job #260120) | Cod sursa (job #850384) | Cod sursa (job #2872413)
#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++, pow *= 2)
h1 += (pow * (cuv[i] - 'a'));
if (Cauta(h1) == 0)
Add(h1);
}
pow = 1;
h1 = 0;
for (i = 0; i < len; i++, pow *= 2)
h1 += pow * (s[i] - 'a');
sol += Cauta(h1);
pow /= 2;
for (i = len; s[i]; i++)
{
h1 /= 2;
h1 += pow * (s[i] - 'a');
sol += Cauta(h1);
}
fout << sol << "\n";
return 0;
}