Pagini recente » Cod sursa (job #505545) | Cod sursa (job #177594) | Cod sursa (job #1781878) | Cod sursa (job #1548890) | Cod sursa (job #1837138)
#include<unordered_map>
#include<iostream>
#include<fstream>
#include<string>
#define M1 24
#define B1 17
using namespace std;
fstream fin("abc2.in",ios::in),fout("abc2.out",ios::out);
int ls,ls1;
unsigned int k1;
unordered_map<unsigned int,int> mp;
string s,s1;
int main()
{
int i,j,c,p=1,r=0;
fin>>s;ls=s.size();
while(fin>>s1)
{
ls1=s1.size();
k1=0;
for(j=0;j<s1.size();j++)
{
c=(s1[j]-'a');
k1=(k1*3+c);
}
//cout<<k1<<"\n";
mp[k1]++;
}
k1=0;
if(ls1<=ls)
{
for(i=0;i<ls1;i++)
{
c=(s[i]-'a');
k1=(k1*3+c);
}
if(mp[k1]!=0) r++;
//cout<<k1<<" "<<mp[k1]<<"\n";
for(i=ls1;i<ls;i++)
{
c=(s[i]-'a');
k1=k1%p;
k1=k1*3+c;
//cout<<k1<<" "<<mp[k1]<<"\n";
if(mp[k1]!=0) r++;
}
}
fout<<r;
}