using System;
using System.Text;
using System.Diagnostics;

// ItoN: Integer to Numeral

class ItoN
{
static int Main(String[] args)
{
   int i = Int32.Parse(args[0]);

   Console.WriteLine((new ItoN()).ConvertIntegerToNumeral(i));

   return 0;
}
String ConvertIntegerToNumeral(int i)
{
   StringBuilder result = new StringBuilder();

   if (i < 100)
   {
      switch (i)
      {
         case 0:
            result.Append("zero");
            break;
         case 1:
            result.Append("one");
            break;
         case 2:
            result.Append("two");
            break;
         case 3:
            result.Append("three");
            break;
         case 4:
            result.Append("four");
            break;
         case 5:
            result.Append("five");
            break;
         case 6:
            result.Append("six");
            break;
         case 7:
            result.Append("seven");
            break;
         case 8:
            result.Append("eight");
            break;
         case 9:
            result.Append("nine");
            break;
         case 10:
            result.Append("ten");
            break;
         case 11:
            result.Append("eleven");
            break;
         case 12:
            result.Append("twelve");
            break;
         case 13:
            result.Append("thirteen");
            break;
         case 14:
            result.Append("fourteen");
            break;
         case 15:
            result.Append("fifteen");
            break;
         case 16:
            result.Append("sixteen");
            break;
         case 17:
            result.Append("seventeen");
            break;
         case 18:
            result.Append("eighteen");
            break;
         case 19:
            result.Append("nineteen");
            break;
         case 20:
            result.Append("twenty");
            break;
         case 30:
            result.Append("thirty");
            break;
         case 40:
            result.Append("fourty");
            break;
         case 50:
            result.Append("fifty");
            break;
         case 60:
            result.Append("sixty");
            break;
         case 70:
            result.Append("seventy");
            break;
         case 80:
            result.Append("eighty");
            break;
         case 90:
            result.Append("ninety");
            break;
         default:
            result.Append(ConvertIntegerToNumeral((i / 10) * 10));
            result.Append(" ");
            result.Append(ConvertIntegerToNumeral(i % 10));
            break;
      }
   }
   else if (i < 1000)
   {
      result.Append(ConvertIntegerToNumeral(i / 100));
      result.Append(" hundred");

      if (i % 100 == 0)
      {
         return result.ToString();
      }

      result.Append(" ");
      result.Append(ConvertIntegerToNumeral(i % 100));
   }
   else if (i < 1000000)
   {
      result.Append(ConvertIntegerToNumeral(i / 1000));
      result.Append(" thousand");

      if (i % 1000 == 0)
      {
         return result.ToString();
      }

      result.Append(" ");
      result.Append(ConvertIntegerToNumeral(i % 1000));
   }
   else if (i < 1000000000)
   {
      result.Append(ConvertIntegerToNumeral(i / 1000000));
      result.Append(" million");

      if (i % 1000000 == 0)
      {
         return result.ToString();
      }

      result.Append(" ");
      result.Append(ConvertIntegerToNumeral(i % 1000000));
   }
   else
   {
      result.Append(ConvertIntegerToNumeral(i / 1000000000));
      result.Append(" billion");

      if (i % 1000000000 == 0)
      {
        
         return result.ToString();
      }

      result.Append(" ");
      result.Append(ConvertIntegerToNumeral(i % 1000000000));
   }

   return result.ToString();
}
}
random/integer_to_numeral.txt · Last modified: 2011/01/05 02:12 by grant