Divide a number into two parts | C ++ implementation of the approach ; Function to print the two parts ; Find the position of 4 ; If current character is not '4' but appears after the first occurrence of '4' ; Print both the parts ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void twoParts ( string str ) { int flag = 0 ; string a = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == '4' ) { str [ i ] = '3' ; a += '1' ; flag = 1 ; } else if ( flag ) a += '0' ; } cout << str << " ▁ " << a ; } int main ( ) { string str = "9441" ; twoParts ( str ) ; return 0 ; }