text: Maximize the decimal equivalent by flipping only a contiguous set of 0 s | C ++ implementation to Maximize the value of the decimal equivalent given in the binary form ; Function to print the binary number ; Check if the current number is 0 ; Find the continuous 0 s ; Replace initially occurring 0 with 1 ; Break out of loop if 1 occurs ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void flip ( string & s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] == '0' ) { while ( s [ i ] == '0' ) { s [ i ] = '1' ; i ++ ; } break ; } } } int main ( ) { string s = "100010001" ; flip ( s ) ; cout << s ; return 0 ; }