Number of sub | C ++ implementation of the approach ; Function to return the count of the required substrings ; To store the final answer ; Loop to find the answer ; Condition to update the answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSubStr ( string str , int len ) { int ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) ans += ( i + 1 ) ; } return ans ; } int main ( ) { string str = "10010" ; int len = str . length ( ) ; cout << countSubStr ( str , len ) ; return 0 ; }