Pagini recente » Cod sursa (job #2849818) | Cod sursa (job #1697590) | Cod sursa (job #1465406) | Cod sursa (job #985484) | Cod sursa (job #104670)
Cod sursa(job #104670)
# include <stdio.h>
# include <string>
using namespace std;
# define input "abc2.in"
# define output "abc2.out"
# define max 10000001
struct abc
{
// int a,b,c;
abc *urma,*urmb,*urmc;
}*dic;
int l,j;
long n,i,rez;
char s[max],cuv[22];
int main()
{
freopen(input,"r",stdin);
freopen(output,"w",stdout);
scanf("%s",s);
scanf("%s",cuv);
l = strlen(cuv);
/*
for(i=1;i<=20*10000000;i++)
{
rez+=i;
if(rez > 603503)
rez-=603503;
}*/
abc * last;
dic = new abc;
/* dic->a=0;
dic->b=0;
dic->c=0;*/
last = dic;
for(i=0;i<l;i++)
{
switch(cuv[i])
{
case 'a':
//last->a = 1;
last->urma = new abc;
last = last->urma; break;
case 'b':
// last->b = 1;
last->urmb = new abc;
last = last->urmb; break;
case 'c':
// last->c = 1;
last->urmc = new abc;
last = last->urmc; break;
}/*
last->a=0;
last->b=0;
last->c=0;*/
}
last = dic;
while(scanf("%s",cuv)!= EOF)
{
last = dic;
for(i=0;i<l;i++)
{
switch(cuv[i])
{
case 'a':
if(last->urma)
last = last->urma;
else
{
// last->a = 1;
last->urma = new abc;
last = last->urma;
// last->a = last->b = last -> c = 0;
}
break;
case 'b':
if(last->urmb)
last = last->urmb;
else
{
// last->b = 1;
last->urmb = new abc;
last = last->urmb;
// last->a = last->b = last->c = 0;
}
break;
case 'c':
if(last->urmc)
last = last->urmc;
else
{
// last->c = 1;
last->urmc = new abc;
last = last->urmc;
// last->a = last->b = last -> c = 0;
}
break;
}
}
}
n = strlen(s);
int ok;
for(i=0;i<n-l+1;++i)
{
ok = 1;
last = dic;
for(j=0;j<l && ok;++j)
{
if(s[i+j] == 'a')
if(!last->urma)
ok=0;
else
last = last->urma;
else
if(s[i+j] == 'b')
if(!last->urmb)
ok=0;
else
last = last->urmb;
else
if(!last->urmc)
ok=0;
else
last = last->urmc;
}
}
if(ok)
++rez;
}
printf("%ld",rez);
return 0;
}