Pagini recente » Cod sursa (job #127838) | Cod sursa (job #307532) | Cod sursa (job #1239063) | Cod sursa (job #2167069) | Cod sursa (job #98569)
Cod sursa(job #98569)
using namespace std;
#include <stdio.h>
#include <string.h>
#include <vector>
#define Lmax 10000002
#define Lcmax 22
//#define Dim 8388607
#define Dim 262143
char s[Lmax],c[Lcmax];
vector<int> h[Dim+1];
vector<int>::iterator it;
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;
for (i=0;i<Lc;++i)
nr=(nr*4)+s[i]-'a';
h[nr % Dim].push_back(nr);
for (i=1;i<=L-Lc;++i)
{
nr=((nr*4)%Nrmax)+s[i+Lc-1]-'a';
h[nr % Dim].push_back(nr);
}
for (i=0,nr=0;i<Lc;++i)
nr=(nr*4)+c[i]-'a';
while (1)
{
for (it=h[nr % Dim].begin();it<h[nr % Dim].end();++it)
if (*it==nr) break;
if (it==h[nr % Dim].end()) break;
++tot;
h[nr % Dim].erase(it);
}
// tot+=h[nr & Dim];
// h[nr & Dim]=0;
while (! feof(stdin))
{
scanf("%s\n",c);
for (i=0,nr=0;i<Lc;++i)
nr=(nr*4)+c[i]-'a';
while (1)
{
for (it=h[nr % Dim].begin();it<h[nr % Dim].end();++it)
if (*it==nr) break;
if (it==h[nr % Dim].end()) break;
++tot;
h[nr % Dim].erase(it);
}
//tot+=h[nr & Dim];
//h[nr & Dim]=0;
}
printf("%d",tot);
fclose(stdin);
fclose(stdout);
return 0;
}