Print all Possible Decodings of a given Digit Sequence | C # program for the above approach ; Function to check if all the characters are lowercase or not ; Traverse the string ; If any character is not found to be in lowerCase ; Function to print the decodings ; If all characters are not in lowercase ; Function to return the character corresponding to given integer ; Function to return the decodings ; Base case ; Recursive call ; Stores the characters of two digit numbers ; Extract first digit and first two digits ; Check if it lies in the range of alphabets ; Next recursive call ; Combine both the output in a single readonly output array ; Index of readonly output array ; Store the elements of output1 in readonly output array ; Store the elements of output2 in readonly output array ; Result the result ; Driver Code ; Function call ; Print function call
using System ; class GFG { public static bool nonLower ( String s ) { for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ! char . IsLower ( s [ i ] ) ) { return true ; } } return false ; } public static void printCodes ( String [ ] output ) { for ( int i = 0 ; i < output . Length ; i ++ ) { if ( nonLower ( output [ i ] ) ) continue ; Console . WriteLine ( output [ i ] ) ; } } public static char getChar ( int n ) { return ( char ) ( n + 96 ) ; } public static String [ ] getCode ( String str ) { if ( str . Length == 0 ) { String [ ] ans = { " " } ; return ans ; } String [ ] output1 = getCode ( str . Substring ( 1 ) ) ; String [ ] output2 = new String [ 0 ] ; int firstDigit = ( str [ 0 ] - '0' ) ; int firstTwoDigit = 0 ; if ( str . Length >= 2 ) { firstTwoDigit = ( str [ 0 ] - '0' ) * 10 + ( str [ 1 ] - '0' ) ; if ( firstTwoDigit >= 10 && firstTwoDigit <= 26 ) { output2 = getCode ( str . Substring ( 2 ) ) ; } } String [ ] output = new String [ output1 . Length + output2 . Length ] ; int k = 0 ; for ( int i = 0 ; i < output1 . Length ; i ++ ) { char ch = getChar ( firstDigit ) ; output [ i ] = ch + output1 [ i ] ; k ++ ; } for ( int i = 0 ; i < output2 . Length ; i ++ ) { char ch = getChar ( firstTwoDigit ) ; output [ k ] = ch + output2 [ i ] ; k ++ ; } return output ; } public static void Main ( String [ ] args ) { String input = "101" ; String [ ] output = getCode ( input ) ; printCodes ( output ) ; } }