Pagini recente » Cod sursa (job #2702916) | Cod sursa (job #1109878) | Cod sursa (job #896450) | Cod sursa (job #653796) | Cod sursa (job #98427)
Cod sursa(job #98427)
using namespace std;
#include <stdio.h>
#include <string.h>
#include <math.h>
#define Lmax 10000001
#define Lcmax 21
#define Dim 8388607
#define golden 1.61803399
char s[Lmax],c[Lcmax];
int h[Lmax];
int L,Lc,tot,i;
long long nr,Nrmax;
int main()
{
freopen("abc2.in","r",stdin);
freopen("abc2.out","w",stdout);
scanf("%s\n",&s);
L=strlen(s);
scanf("%s\n",&c);
Lc=strlen(c);
Nrmax=(1<<Lc);
Nrmax=Nrmax*Nrmax-1;
for (i=0;i<Lc;++i)
nr=(nr*4)+s[i]-'a';
++h[int(nr*1.61803399) & Dim];
for (i=1;i<=L-Lc;++i)
{
nr=((nr*4)&Nrmax)+s[i+Lc-1]-'a';
++h[int(nr*1.61803399) & Dim];
}
for (i=0,nr=0;i<Lc;++i)
nr=(nr*4)+c[i]-'a';
tot+=h[int(nr*1.61803399) & Dim];
h[int(nr*1.61803399) & Dim]=0;
while (! feof(stdin))
{
scanf("%s\n",c);
for (i=0,nr=0;i<Lc;++i)
nr=(nr*4)+c[i]-'a';
tot+=h[int(nr*1.61803399) & Dim];
h[int(nr*1.61803399) & Dim]=0;
}
printf("%d",tot);
fclose(stdin);
fclose(stdout);
return 0;
}