vonko1988

c#0to999_version2

Mar 18th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.12 KB | None | 0 0
  1. using System;
  2.  
  3. class Number0to999InBulgarian_ver2
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please enter a number between 0 and 999: ");
  8.         string input = Console.ReadLine();
  9.  
  10.         string[] ones = new String[]{"", "едно", "две", "три", "четири", "пет",
  11.                          "шест", "седем", "осем", "девет"};
  12.         string[] tens = new String[]{"", "", "двадесет", "тридесет", "четиредесет",
  13.                          "петдесет", "шестдесет", "седемдесет", "осемдесет", "деветдесет"};
  14.         string[] specialNumbers = new String[]{"десет", "единадесет", "дванадесет", "тринадесет",
  15.                                   "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет",
  16.                                   "осемнадесет", "деветнадесет"};
  17.         int length = input.Length;
  18.         int number = 0;
  19.  
  20.  
  21.         try
  22.         {
  23.             number = int.Parse(input);
  24.         }
  25.         catch (FormatException)
  26.         {
  27.             Console.WriteLine("Моля въведете валидно число!");
  28.             return;
  29.         }
  30.  
  31.         int index = number / 100;
  32.         int index1 = (number / 10) % 10;
  33.         int index2 = (number % 100) % 10;
  34.  
  35.         if (length == 1)
  36.         {
  37.             if (input[0] == '0')
  38.             {
  39.                 Console.WriteLine("Числото е нула!");
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine(ones[index2]);
  44.             }
  45.         }
  46.  
  47.         else if (length == 2)
  48.         {
  49.             if (input[0] == '1')
  50.             {
  51.                 Console.WriteLine(specialNumbers[index2]);
  52.             }
  53.             else
  54.             {
  55.                 if (input[1] == '0')
  56.                 {
  57.                     Console.WriteLine(tens[index1]);
  58.                 }
  59.                 else
  60.                 {
  61.                     Console.WriteLine(tens[index1] + " и " + ones[index2]);
  62.                 }
  63.             }
  64.         }
  65.  
  66.         else if (length == 3)
  67.         {
  68.             if (input[1] == '0' && input[2] == '0')
  69.             {
  70.                 if (index == 1)
  71.                 {
  72.                     Console.WriteLine("сто");
  73.                 }
  74.                 else if (index < 4)
  75.                 {
  76.                     Console.WriteLine(ones[index] + "стa " + tens[index1] + " " + ones[index2]);
  77.                 }
  78.                 else
  79.                 {
  80.                     Console.WriteLine(ones[index] + "стотин " + tens[index1] + " " + ones[index2]);
  81.                 }
  82.             }
  83.  
  84.             else if (input[1] == '0')
  85.             {
  86.                 if (input[0] == '1')
  87.                 {
  88.                     Console.WriteLine("сто и " + ones[index2]);
  89.                 }
  90.  
  91.                 else if (input[0] != 1 && input[2] != '0')
  92.                 {
  93.                     Console.WriteLine(ones[index] + "стотин и " + ones[index2]);
  94.                 }
  95.             }
  96.  
  97.             else if (input[1] == '1')
  98.             {
  99.                 if (input[0] == '1')
  100.                 {
  101.                     Console.WriteLine("сто и " + specialNumbers[index2]);
  102.                 }
  103.                 else
  104.                 {
  105.                     if (index < 4)
  106.                     {
  107.                         Console.WriteLine(ones[index] + "ста и " + specialNumbers[index1]);
  108.                     }
  109.                     else
  110.                     {
  111.                         Console.WriteLine(ones[index] + "стотин и " + specialNumbers[index1]);
  112.                     }
  113.                 }
  114.             }
  115.  
  116.             else if (input[1] != '0' && input[1] != '1')
  117.             {
  118.                 if (input[0] == '1')
  119.                 {
  120.                     if (input[2] == '0')
  121.                     {
  122.                         Console.WriteLine("сто" + " и " + tens[index1]);
  123.                     }
  124.                     else
  125.                     {
  126.                         Console.WriteLine("сто " + tens[index1] + " и " + ones[index2]);
  127.                     }
  128.                 }
  129.  
  130.                 else if (input[1] != '0' || input[2] != '0')
  131.                 {
  132.                     if (input[2] == '0')
  133.                     {
  134.                         if (index < 4)
  135.                         {
  136.                             Console.WriteLine(ones[index] + "ста" + " и " + tens[index1]);
  137.                         }
  138.                         else
  139.                         {
  140.                             Console.WriteLine(ones[index] + "стотин" + " и " + tens[index1]);
  141.                         }
  142.                     }
  143.                     else
  144.                     {
  145.                         Console.WriteLine(ones[index] + "стотин и " + tens[index1] + " и " + ones[index2]);
  146.                     }
  147.                 }
  148.             }
  149.         }
  150.  
  151.         else
  152.         {
  153.             Console.WriteLine("Моля въведете трицифрено число!");
  154.         }
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment