Dev Skill DCP-496: Only '1' Substrings !! Solution
Problem Link
Dev Skill DCP-496: Only '1' Substrings !! Solution
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int ch=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='1')
{
ch++;
for(int j=i+1;j<s.size();j++)
{
if(s[j]=='1')
ch++;
else
break;
}
}
}
cout<<ch<<endl;
}
return 0;
}
No comments