text: Print characters and their frequencies in order of occurrence | C ++ implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void prCharWithFreq ( string s ) { unordered_map < char , int > d ; for ( char i : s ) { d [ i ] ++ ; } for ( char i : s ) { if ( d [ i ] != 0 ) { cout << i << d [ i ] << " ▁ " ; d [ i ] = 0 ; } } } int main ( ) { string s = " geeksforgeeks " ; prCharWithFreq ( s ) ; }