Maximum number of splits of a binary number | C ++ implementation of the approach ; Function to return the required count ; If the splitting is not possible ; To store the final ans ; Counting the number of zeros ; Return the final answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int cntSplits ( string s ) { if ( s [ s . size ( ) - 1 ] == '1' ) return -1 ; int ans = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) ans += ( s [ i ] == '0' ) ; return ans ; } int main ( ) { string s = "10010" ; cout << cntSplits ( s ) ; return 0 ; }