Advertisement
fbinnzhivko

1000 with words

Sep 14th, 2016
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. class NumberWord
  3.     {
  4.         static string[] one = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
  5.         static string[] teens = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeeen", "eighteen", "nineteen" };
  6.         static string[] ten = { null, null, "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  7.  
  8.         static void Main()
  9.         {
  10.  
  11.             int a = int.Parse(Console.ReadLine());
  12.  
  13.             int hundreds = a / 100;
  14.             int tens = (a / 10) % 10;
  15.             int ones = a % 10;
  16.             string wordRepresentation = "";
  17.  
  18.             if (hundreds == 0)
  19.             {
  20.                 if (tens == 0)
  21.                 {
  22.                     wordRepresentation = one[ones];
  23.                 }
  24.                 else
  25.                 {
  26.                     if (tens == 1)
  27.                     {
  28.                         wordRepresentation = teens[ones];
  29.                     }
  30.                     else
  31.                     {
  32.                         wordRepresentation = ten[tens];
  33.                         if (ones > 0)
  34.                         {
  35.                             wordRepresentation += " " + one[ones];
  36.                         }
  37.                     }
  38.                 }
  39.             }
  40.             else
  41.             {
  42.                 wordRepresentation = one[hundreds] + " hundred";
  43.                 if (tens == 0)
  44.                 {
  45.                     if (ones != 0)
  46.                     {
  47.                         wordRepresentation += " and " + one[ones];
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     if (tens == 1)
  53.                     {
  54.                         wordRepresentation += " and " + teens[ones];
  55.                     }
  56.                     else
  57.                     {
  58.                         wordRepresentation += " and " + ten[tens];
  59.                         if (ones > 0)
  60.                         {
  61.                             wordRepresentation += " " + one[ones];
  62.                         }
  63.                     }
  64.                 }
  65.             }
  66.             Console.WriteLine("{0} = {1}", a, wordRepresentation);
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement