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
using System ; using System . Collections . Generic ; class GFG { static void generateLetters ( string S , int P , Dictionary < char , char > M ) { if ( P == S . Length ) { Console . WriteLine ( S ) ; return ; } generateLetters ( S , P + 1 , M ) ; S = S . Substring ( 0 , P ) + M [ S [ P ] ] + S . Substring ( P + 1 ) ; generateLetters ( S , P + 1 , M ) ; return ; } public static void Main ( ) { string S = " aBc " ; Dictionary < char , char > M = new Dictionary < char , char > ( ) ; M . Add ( ' a ' , ' $ ' ) ; M . Add ( ' B ' , ' # ' ) ; M . Add ( ' c ' , ' ^ ' ) ; M . Add ( ' d ' , ' & ' ) ; M . Add ( '1' , ' * ' ) ; M . Add ( '2' , ' ! ' ) ; M . Add ( ' E ' , ' @ ' ) ; generateLetters ( S , 0 , M ) ; } }