Pagini recente » Cod sursa (job #2584185) | Cod sursa (job #1850741) | Cod sursa (job #947027) | Cod sursa (job #569925) | Cod sursa (job #2452312)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f ("abc2.in");
ofstream g ("abc2.out");
string s;
string t;
long long a,b;
vector<long long > vek;
long long lenstr, texlen;
long long mod=29989;
long long abmodc(long long a,long long b)
{
// a^b mod c
if(a % mod == 0)
return 0;
long long res=1;
while(b)
{
if(b%2==1)
res = (res * a) % mod;
b /= 2;
a = (a * a) % mod;
}
return res;
}
int main()
{
f>>s;
while(f>>t)
{
lenstr=t.size();
a=0;
for(long long i=0;i<=t.size()-1;++i)
{
a*=4;
a+=t.at(i)-'a'+1;
}
vek.push_back(a);
// g<<a<<" "<<t<<"\n ";
}
long long pow=abmodc(4, lenstr-1);
texlen=s.size();
long long ko=0;
b=0;
for(long long i=0;i<s.size();++i)
{
b%=pow;
b*=4;
b+=s.at(i)-'a'+1;
if(i>=lenstr-1)
{
// g<<"b-> "<<b<<" "<<s<<"\n";
if(find(vek.begin(), vek.end(), b)!=vek.end())
ko++;
}
}
g<<ko;
return 0;
}