Removing elements between the two zeros | C ++ program to delete elements between zeros ; Function to find the string after operation ; Travesing through string ; Checking for character Between two zeros ; deleting the character At specific position ; updating the length of the string ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findstring ( string s ) { int n = s . length ( ) ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( s . at ( i - 1 ) == '0' && s . at ( i + 1 ) == '0' ) ) { s . erase ( i , 1 ) ; i -- ; if ( i > 0 && s . at ( i - 1 ) == '0' ) i -- ; n = s . length ( ) ; } } return s ; } int main ( ) { cout << findstring ( "100100" ) ; return 0 ; }