Description
计算机数据都是由0和1组成的,看着长长的0101001110101111011,要找出连续n个1的子串有多少个,确实麻烦,请你编程实现吧。
Input
输入第一行为一个字符串,由0和1组成,长度小于1000;输入第二行为一个正整数n。
Output
输出一个整数,表示连续n个的1的子串的个数。
Sample Input
01010011101011110112
Sample Output
6
HINT
Source
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char str[1005];
gets(str);
int i,j;
int len=strlen(str);
int m;
int count,sum=0;
scanf("%d",&m);
for(i=0; i<len; i++)
{
count=1;
if(str[i]=='1'&&m!=1)
{
for(j=i+1; j<i+m; j++)
{
if(str[j]!='1')
break;
else
count++;
}
}
if(count==m)
sum++;
}
printf("%d",sum);
return 0;
}