Convert the number from International system to Indian system | C ++ program to convert the number from International system to Indian system ; Function to convert a number represented in International numeric system to Indian numeric system . ; Find the length of the input string ; Removing all the separators ( , ) from the input string ; Reverse the input string ; Declaring the output string ; Process the input string ; Add a separator ( , ) after the third number ; Then add a separator ( , ) after every second number ; Reverse the output string ; Return the output string back to the main function ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string convert ( string input ) { int len = input . length ( ) ; for ( int i = 0 ; i < len ; ) { if ( input [ i ] == ' , ▁ ' ) { input . erase ( input . begin ( ) + i ) ; len -- ; i -- ; } else if ( input [ i ] == ' ▁ ' ) { input . erase ( input . begin ( ) + i ) ; len -- ; i -- ; } else { i ++ ; } } reverse ( input . begin ( ) , input . end ( ) ) ; string output ; for ( int i = 0 ; i < len ; i ++ ) { if ( i == 2 ) { output += input [ i ] ; output += " , ▁ " ; } else if ( i > 2 && i % 2 == 0 && i + 1 < len ) { output += input [ i ] ; output += " , ▁ " ; } else { output += input [ i ] ; } } reverse ( output . begin ( ) , output . end ( ) ) ; return output ; } int main ( ) { string input1 = "123 , ▁ 456 , ▁ 789" ; string input2 = "90 , ▁ 050 , ▁ 000 , ▁ 000" ; cout << convert ( input1 ) << endl ; cout << convert ( input2 ) ; }