Pagini recente » Cod sursa (job #853285) | Borderou de evaluare (job #630578) | Borderou de evaluare (job #2420884) | Monitorul de evaluare | Cod sursa (job #531055)
Cod sursa(job #531055)
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
const char InFile[]="abc2.in";
const char OutFile[]="abc2.out";
const unsigned int MaxN=10111000;
const unsigned int MaxL=50;
const unsigned int MaxK=66111;
ifstream fin(InFile);
ofstream fout(OutFile);
char str[MaxN],cuv[MaxL];
unsigned int N,L,sol,cpow,cod,C[MaxK],K,tstep;
inline unsigned int get(unsigned int key)
{
int step=tstep,pos;
for(pos=0;step;step>>=1)
{
if((pos|step)<=K && C[pos|step]<=key)
{
pos|=step;
}
}
return C[pos]==key;
}
int main()
{
fin.getline(str,sizeof(str));
N=strlen(str);
K=-1;
while(fin.getline(cuv,sizeof(cuv)))
{
if(L==0)
{
L=strlen(cuv);
}
cod=0;
for(register unsigned int i=0;i<L;++i)
{
cod*=3;
cod+=cuv[i]-'a';
cuv[i]=0;
}
C[++K]=cod;
}
fin.close();
sort(C,C+K+1);
for(tstep=1;tstep<=K;tstep<<=1);
cpow=1;
for(register unsigned int i=1;i<L;++i)
{
cpow*=3;
}
cod=0;
for(register unsigned int i=0;i<L;++i)
{
str[i]-='a';
cod*=3;
cod+=str[i];
}
sol+=get(cod);
for(register unsigned int i=L;i<N;++i)
{
str[i]-='a';
cod-=cpow*str[i-L];
cod*=3;
cod+=str[i];
sol+=get(cod);
}
fout<<sol;
fout.close();
return 0;
}