Advertisement
GeorgiPopov

Numbers_to_Words 2

May 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Numbers_to_Words
  8. {
  9. class Numbers_to_Words
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14.  
  15. int numCount = int.Parse(Console.ReadLine());
  16.  
  17. for (int i = 0; i < numCount; i++)
  18. {
  19.  
  20. var currentNum = int.Parse(Console.ReadLine());
  21. //Console.WriteLine(Letterize(currentNum));
  22.  
  23. // Valid ot not valid currentNum
  24. if (currentNum > 999)
  25. {
  26. Console.WriteLine("too large");
  27. continue;
  28. }
  29.  
  30. else if (currentNum < -999)
  31. {
  32. Console.WriteLine("too small");
  33. continue;
  34. }
  35.  
  36. else if (currentNum >= -99 && currentNum <= 99)
  37. {
  38. continue;
  39. }
  40.  
  41.  
  42. var hundredDigitOfCurrentNum = (Math.Abs(currentNum) / 10) / 10;
  43. var tenthsDigitsOfCurrentNum = (Math.Abs(currentNum) / 10) % 10;
  44. var singlesDigitsOfCurrenrNum = Math.Abs(currentNum) % 10;
  45.  
  46. var hundredPositionResult = string.Empty;
  47. var tenthsPositionResult = string.Empty;
  48. var singlesPositionResult = string.Empty;
  49.  
  50. // Discovery of the hundreds
  51. switch (hundredDigitOfCurrentNum)
  52. {
  53. case 1:
  54. hundredPositionResult = "one-hundred";
  55. break;
  56. case 2:
  57. hundredPositionResult = "two-hundred";
  58. break;
  59. case 3:
  60. hundredPositionResult = "three-hundred";
  61. break;
  62. case 4:
  63. hundredPositionResult = "four-hundred";
  64. break;
  65. case 5:
  66. hundredPositionResult = "five-hundred";
  67. break;
  68. case 6:
  69. hundredPositionResult = "six-hundred";
  70. break;
  71. case 7:
  72. hundredPositionResult = "seven-hundred";
  73. break;
  74. case 8:
  75. hundredPositionResult = "eight-hundred";
  76. break;
  77. case 9:
  78. hundredPositionResult = "nine-hundred";
  79. break;
  80. }
  81.  
  82. //Find the numbers up to 10
  83. if (tenthsDigitsOfCurrentNum != 1)
  84. {
  85. switch (singlesDigitsOfCurrenrNum)
  86. {
  87. case 1:
  88. singlesPositionResult = "one";
  89. break;
  90. case 2:
  91. singlesPositionResult = "two";
  92. break;
  93. case 3:
  94. singlesPositionResult = "three";
  95. break;
  96. case 4:
  97. singlesPositionResult = "four";
  98. break;
  99. case 5:
  100. singlesPositionResult = "five";
  101. break;
  102. case 6:
  103. singlesPositionResult = "six";
  104. break;
  105. case 7:
  106. singlesPositionResult = "seven";
  107. break;
  108. case 8:
  109. singlesPositionResult = "eight";
  110. break;
  111. case 9:
  112. singlesPositionResult = "nine";
  113. break;
  114. }
  115. }
  116. // Detection of special cases in the case of tens
  117. else if (tenthsDigitsOfCurrentNum == 1)
  118. {
  119. switch (singlesDigitsOfCurrenrNum)
  120. {
  121. case 0:
  122. tenthsPositionResult = "ten";
  123. break;
  124. case 1:
  125. tenthsPositionResult = "eleven";
  126. break;
  127. case 2:
  128. tenthsPositionResult = "twelve";
  129. break;
  130. case 3:
  131. tenthsPositionResult = "thirteen";
  132. break;
  133. case 4:
  134. tenthsPositionResult = "fourteen";
  135. break;
  136. case 5:
  137. tenthsPositionResult = "fifteen";
  138. break;
  139. case 6:
  140. tenthsPositionResult = "sixteen";
  141. break;
  142. case 7:
  143. tenthsPositionResult = "seventeen";
  144. break;
  145. case 8:
  146. tenthsPositionResult = "eighteen";
  147. break;
  148. case 9:
  149. tenthsPositionResult = "nineteen";
  150. break;
  151. }
  152. }
  153. //Find the position of the tenths
  154. switch (tenthsDigitsOfCurrentNum)
  155. {
  156. case 2:
  157. tenthsPositionResult = "twenty";
  158. break;
  159. case 3:
  160. tenthsPositionResult = "thirty";
  161. break;
  162. case 4:
  163. tenthsPositionResult = "forty";
  164. break;
  165. case 5:
  166. tenthsPositionResult = "fifty";
  167. break;
  168. case 6:
  169. tenthsPositionResult = "sixty";
  170. break;
  171. case 7:
  172. tenthsPositionResult = "seventy";
  173. break;
  174. case 8:
  175. tenthsPositionResult = "eighty";
  176. break;
  177. case 9:
  178. tenthsPositionResult = "ninety";
  179. break;
  180. }
  181.  
  182. //Printing
  183. if (currentNum < 0)
  184. {
  185. hundredPositionResult = "minus " + hundredPositionResult;
  186. }
  187.  
  188. if (tenthsDigitsOfCurrentNum == 0 && singlesDigitsOfCurrenrNum == 0)
  189. {
  190. Console.WriteLine(hundredPositionResult);
  191. }
  192. else if (tenthsDigitsOfCurrentNum == 0 && singlesDigitsOfCurrenrNum != 0)
  193. {
  194. Console.WriteLine($"{hundredPositionResult} and {singlesPositionResult}");
  195. }
  196. else if (tenthsDigitsOfCurrentNum != 0 && singlesDigitsOfCurrenrNum == 0)
  197. {
  198. Console.WriteLine($"{hundredPositionResult} and {tenthsPositionResult}");
  199. }
  200. else
  201. {
  202. Console.WriteLine($"{hundredPositionResult} and {tenthsPositionResult} {singlesPositionResult}");
  203. }
  204.  
  205.  
  206. }
  207. }
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement