using System;
public class NumberTranslation
{
public static int GetTranslationCount(int number)
{
if(number <= 0)
{
return 0;
}
string numberInString = number.ToString();
return GetTranslationCount(numberInString);
}
private static int GetTranslationCount(string number)
{
int length = number.Length;
int[] counts = new int[length];
for(int i = length - 1; i >= 0; --i)
{
int count = 0;
if(number[i] >= '1' && number[i] <= '9')
{
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 <= 26)
{
if(i < length - 2)
{
count += counts[i + 2];
}
else
{
count += 1;
}
}
}
counts[i] = count;
}
return counts[0];
}
// ------------------ Test Code ------------------
private static void Test(string testName, int number, int expected)
{
if(GetTranslationCount(number) == expected)
{
Console.WriteLine(testName + " passed.");
}
else
{
Console.WriteLine(testName + " FAILED.");
}
}
private static void Test1()
{
int number = 1;
int expected = 1;
Test("Test1", number, expected);
}
private static void Test2()
{
int number = 11;
int expected = 2;
Test("Test2", number, expected);
}
private static void Test3()
{
int number = 126;
int expected = 3;
Test("Test3", number, expected);
}
private static void Test4()
{
int number = 127;
int expected = 2;
Test("Test4", number, expected);
}
private static void Test5()
{
int number = 427;
int expected = 1;
Test("Test5", number, expected);
}
private static void Test6()
{
int number = 100;
int expected = 0;
Test("Test6", number, expected);
}
private static void Test7()
{
int number = 101;
int expected = 1;
Test("Test7", number, expected);
}
private static void Test8()
{
int number = 12258;
int expected = 5;
Test("Test8", number, expected);
}
public static void Main()
{
Test1();
Test2();
Test3();
Test4();
Test5();
Test6();
Test7();
Test8();
}
}