1 0-25 a-z
// face questions 46: translated into digital string // Title: given a number, we follow the following rules to translate a string: 0 translate "a", 1 turn // translated "b", ... ..., translated into 11 "l", ......, 25 translated into "z". There may be more than a digital translation. Example // The 12258 has five different translations, which are "bccfi", "bwfi", "bczi", "mcfi" and // "MZI." Please programming function for a number of different methods to calculate a number have translation. #include < String > #include <the iostream> the using namespace STD; int GetTranslationCount ( const String & Number); int GetTranslationCount ( int Number) { IF (Number < String numberInString the to_string = (Number); // convert to a string return GetTranslationCount (numberInString); } int GetTranslationCount ( const String & Number) { int length = number.length (); int * Counts = new new int [length]; int = COUNT 0 ; for ( int I = length - . 1 ; I> = 0 ; Inc. (www.i-levelmedia.com)) // right start to avoid duplication of sub-problems recursively encountered { COUNT = 0 ; if (i < length - 1) count = counts[i + 1]; else count = 1; if (i < length - 1) { int digit1 = number[i] - '0'; int digit2 = number[i + 1] - '0'; int converted = digit1 * 10 + digit2; if (converted >= 10 && converted <= 25)// condition is satisfied, the current position of the recording times for all possible { IF (I <length - 2 ) // bit dynamic programming means COUNT + = Counts [I + 2 ]; the else COUNT + = . 1 ; } } Counts [I] = COUNT; } COUNT = counts [ 0 ]; // returns first value counts Delete [] counts; return COUNT; }