Fazil's faculty gave him a string S consisting of only 1s and 0s and he need to find the number of substrings which start and end both in 1.In this problem, a substring is defined as a sequence of continuous characters S
#include <stdio.h>
#include<string.h>
int main()
{
char string;
int string1,test;
scanf("%d",&test);
while(test--)
{
int sum=0,i;
scanf("%d",&string1);
char str[string1];
scanf("%s",str);
for(i=0;i<strlen(str);i++)
if(str[i]=='1') sum++;
int ans=sum*(sum+1)/2;
printf("%d\n",ans);
}
scanf("%c",&string);
return 0;
}
Comments
Post a Comment