Pagini recente » Cod sursa (job #1954974) | Cod sursa (job #1790645) | Cod sursa (job #2531540) | Cod sursa (job #1175724) | Cod sursa (job #2102449)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("abc2.in");
ofstream out("abc2.out");
const int maxn = 10000005;
const int mod = 30000;
vector <long long> hsh[mod + 5];
string text;
int v[maxn];
inline void push(long long x)
{
int p = x % mod;
hsh[p].push_back(x);
}
inline bool searchfor(long long x)
{
int p = x % mod;
for(auto it : hsh[p])
if(it == x)
return 1;
return 0;
}
int main()
{
cin.sync_with_stdio(0);
in >> text;
for(int i = 0; i < text.size(); i++)
v[i] = text[i] - 'a';
string cuv;
while(in >> cuv)
{
long long p = 0;
for(auto it : cuv)
p = p * 3 + it - 'a';
push(p);
}
int lg = cuv.size();
int sz = text.size();
long long put3 = 1;
long long a = 0;
for(int i = 0; i < lg; i++)
{
a = a * 3 + v[i];
if(i != 0)
put3 = put3 * 3;
}
int nr = 0;
for(int i = lg; i < sz; i++)
{
if(searchfor(a) == 1)
nr++;
a = a - put3 * v[i - lg];
a = a * 3 + v[i];
}
if(searchfor(a) == 1)
nr++;
out << nr << "\n";
return 0;
}