Sub string number
Sub string number:
code:
#include<stdio.h>
int main()
{
char s1[50],s2[50];
int i,j,k,sn=0;
gets(s1);
fflush(stdin);
gets(s2);
for(i=0;s1[i]!='\0';i++)
{
if(s1[i]==s2[0])
{
for(j=i+1,k=1;s2[k]!='\0';k++,j++)
{
if(s1[j]!=s2[k])
break;
}
if(s2[k]=='\0')
sn++;
}
}
printf("%d ",sn);
return 0;
}
Example:
input:
case1:
S1: Subir Saha
S2: bir
case2:
S1: Bangladesh
S2: bang
case3:
S1: gooogle
S2: oo
output:
case1:
1
case2:
0
case3:
2
code:
#include<stdio.h>
int main()
{
char s1[50],s2[50];
int i,j,k,sn=0;
gets(s1);
fflush(stdin);
gets(s2);
for(i=0;s1[i]!='\0';i++)
{
if(s1[i]==s2[0])
{
for(j=i+1,k=1;s2[k]!='\0';k++,j++)
{
if(s1[j]!=s2[k])
break;
}
if(s2[k]=='\0')
sn++;
}
}
printf("%d ",sn);
return 0;
}
Example:
input:
case1:
S1: Subir Saha
S2: bir
case2:
S1: Bangladesh
S2: bang
case3:
S1: gooogle
S2: oo
output:
case1:
1
case2:
0
case3:
2
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন