Pagini recente » Cod sursa (job #118341) | Cod sursa (job #2833989) | Cod sursa (job #1266859) | Cod sursa (job #649809) | Cod sursa (job #104673)
Cod sursa(job #104673)
# 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);
abc * last;
dic = new abc;
last = dic;
for(i=0;i<l;i++)
{
switch(cuv[i])
{
case 'a':
last->urma = new abc;
last = last->urma; break;
case 'b':
last->urmb = new abc;
last = last->urmb; break;
case 'c':
last->urmc = new abc;
last = last->urmc; break;
}
}
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->urma = new abc;
last = last->urma;
}
break;
case 'b':
if(last->urmb)
last = last->urmb;
else
{
last->urmb = new abc;
last = last->urmb;
}
break;
case 'c':
if(last->urmc)
last = last->urmc;
else
{
last->urmc = new abc;
last = last->urmc;
}
break;
}
}
}
n = strlen(s);
for(i=0;i<n-l+1;++i)
{
last = dic;
for(j=0;j<l;++j)
{
if(s[i+j] == 'a')
if(!last->urma)
break;
else
last = last->urma;
else
if(s[i+j] == 'b')
if(!last->urmb)
break;
else
last = last->urmb;
else
if(!last->urmc)
break;
else
last = last->urmc;
}
if(j == l)
++rez;
}
printf("%ld",rez);
return 0;
}