Printing frequency of each character just after its consecutive occurrences | CPP program to print run length encoding of a string ; Counting occurrences of s [ i ] ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printRLE ( string s ) { for ( int i = 0 ; s [ i ] != ' \0' ; i ++ ) { int count = 1 ; while ( s [ i ] == s [ i + 1 ] ) { i ++ ; count ++ ; } cout << s [ i ] << count << " ▁ " ; } cout << endl ; } int main ( ) { printRLE ( " GeeeEEKKKss " ) ; printRLE ( " ccccOddEEE " ) ; return 0 ; }