STRING FACTOR

Description:

The success of IEEE code-quest depends on number of times the factor is present in a given string.Help core members to find them Factor of string is defined as a substring.In this case it's '01'. Input First line of input contains an integer T, denoting the number of test cases. Then follows description of T cases.Each line of input is a binary form. Output Print the number of times the factor is present in a given string. Constraints 1 <= S <= 100000 1 <= T <= 50 Test Case 1 Input (stdin) 2 1001010100001 100101 Expected Output 4 2 Test Case 2 Input (stdin) 1 10001000101 Expected Output 3

Program :

  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      int t,i,n,c;
      char s[100001];
      scanf("%d",&t);
      while(t--)
      {
        c=0;
        scanf("%s",s);
        n=strlen(s);
        for(i=1;i<n;i++)
        {
          if(s[i-1]=='0' && s[i]=='1')
            c++;
        }
        printf("%d\n",c);
      }

    return 0;
    }