text: Remove even frequency characters from the string | C ++ implementation of the approach ; Function that removes the characters which have even frequencies in the string ; create a map to store the frequency of each character ; to store the new string ; remove the characters which have even frequencies ; if the character has even frequency then skip ; else concatenate the character to the new string ; display the modified string ; Driver code ; remove the characters which have even frequencies
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void solve ( string s ) { unordered_map < char , int > m ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { m [ s [ i ] ] ++ ; } string new_string = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( m [ s [ i ] ] % 2 == 0 ) continue ; new_string += s [ i ] ; } cout << new_string << endl ; } int main ( ) { string s = " aabbbddeeecc " ; solve ( s ) ; return 0 ; }