Decode a given string by removing duplicate occurrences | C ++ program for the above approach ; Function to count the appearances of each character ; If the character is lower case ; If the character is uppercase ; If the character is a punctuation mark ; Function to decode the given encoded string ; Iterate the given string str ; Find the index of the next character to be printed ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findRepitition ( char a ) { if ( a <= ' z ' && a >= ' a ' ) { return a - ' a ' ; } else if ( a <= ' Z ' && a >= ' A ' ) { return a - ' A ' ; } return 0 ; } void decodeString ( string str ) { string output = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { output . push_back ( str [ i ] ) ; i += findRepitition ( str [ i ] ) ; } cout << " Decrypted ▁ code ▁ is ▁ { " << output << " } " << endl ; } int main ( ) { string str = " abbbb ▁ acccdddd " ; decodeString ( str ) ; return 0 ; }