Pagini recente » Cod sursa (job #575570) | Cod sursa (job #3142481) | Cod sursa (job #997122) | Cod sursa (job #1051265) | Cod sursa (job #413015)
Cod sursa(job #413015)
using namespace std;
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
set<unsigned> S;
char s[10000005], c[25];
unsigned Val(char * s, int nC){
int NR=0;
for(int i=0;i<nC;++i)
NR=3*NR+s[i]-'a';
return NR;
}
int main(){
freopen("abc2.in","r",stdin);
//int nS=0;
//while((ch=fin.get())>='a') s[nS++]=ch;
//s[nS]=0;
fgets(s,10000005,stdin);
fgets(c,25,stdin);
//cout<<s<<endl<<endl;
//cout.flush();
int nC=strlen(c)-1;
S.insert(Val(c,nC) );
while(fgets(c,25,stdin))
S.insert(Val(c,nC));
int rez=0;
int NR=0;
unsigned P=1;
for(int i=0;i<nC;++i)
NR=3*NR+s[i]-'a',P*=3;
P/=3;
if(S.find(NR)!=S.end())
++rez;
for(int i=nC;s[i]>='a';++i){
NR%=P;
NR = 3*NR + s[i]-'a';
if(S.find(NR)!=S.end())
++rez;
}
freopen("abc2.out","w",stdout);
printf("%d\n",rez);
return 0;
}