问题一百二十三:统计子串

Description

输入一个字符串str和一个子串s,统计str中子串s的个数。 

Input

输入数据有2行,第一行为str,第二行为s,字符串长度不超过128。

Output

输出子串的个数

Sample Input


sdf$$$sdf$$
sdf

Sample Output


2

 

#include <stdio.h>
#include <string.h>

int main()
{
        int i;
		int j;
		int l;
		int n;
		int m;
		int count;
		int flag;
		char a[129];
		char b[129];

		gets(a);
		gets(b);

		n=strlen(a);
		m=strlen(b);
        count=0;

		for(i=0; i<n; i++)
		{   
			flag=1;
			j=0;
			if(a[i]==b[j])
			{   
				l=i;
			    for(j=1; j<m; j++)
				{
					 if(b[j]!=a[++l])
					 {
						 flag=0;
					    break;
					 }
				}

				if(flag)
				{
			       count++;
				}
			}
			
		}

        printf("%d", count);

	   return 0;
}

   

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值