Generate all possible strings formed by replacing letters with given respective symbols | C ++ program for the above approach ; Function to generate all possible string by replacing the characters with mapped symbols ; Base Case ; Function call with the P - th character not replaced ; Replace the P - th character ; Function call with the P - th character replaced ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void generateLetters ( string S , int P , unordered_map < char , char > M ) { if ( P == S . size ( ) ) { cout << S << " STRNEWLINE " ; return ; } generateLetters ( S , P + 1 , M ) ; S [ P ] = M [ S [ P ] ] ; generateLetters ( S , P + 1 , M ) ; return ; } int main ( ) { string S = " aBc " ; unordered_map < char , char > M ; M [ ' a ' ] = ' $ ' ; M [ ' B ' ] = ' # ' ; M [ ' c ' ] = ' ^ ' ; M [ ' d ' ] = ' & ' ; M [ '1' ] = ' * ' ; M [ '2' ] = ' ! ' ; M [ ' E ' ] = ' @ ' ; generateLetters ( S , 0 , M ) ; return 0 ; }