Advertisement
JulianJulianov

01DataTypeFinder with 4. & .4 is double

Oct 12th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 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 _01DataTypeFinder
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = Console.ReadLine();
  14.  
  15. int position = 0;
  16. string dataType = "";
  17. int countAllSymbol = 0;
  18. int countSymbol = 0;
  19. int countPoint = 0;
  20. int countMinus = 0;
  21. int countOther = 0;
  22. int countDigit = 0;
  23. char charSymbol = ' ';
  24. int beforePoint = 0;
  25. int afterPoint = 0;
  26. int beforeDigitMinus = 0;
  27. int afterDigitMinus = 0;
  28. char firstSymbol = ' ';
  29. char secondSymbol = ' ';
  30. int integer = 0;
  31. double floating = 0.0;
  32. while (input != "END")
  33. {
  34. foreach (var item in input)
  35. {
  36. if (Char.IsDigit(item) == true)
  37. {
  38. countDigit++;
  39. position = (int)Char.GetNumericValue(item);
  40. countAllSymbol++;
  41. if (countPoint == 0 && countAllSymbol > 0)
  42. {
  43. beforePoint++;
  44. }
  45. else if (charSymbol == '.')
  46. {
  47. afterPoint++;
  48. }
  49. if (countMinus == 1 && countSymbol == 1)
  50. {
  51. beforeDigitMinus++;
  52. }
  53. else if (charSymbol == '-')
  54. {
  55. afterDigitMinus++;
  56. }
  57. if (input.Length == countAllSymbol && countOther == 0 && countPoint == 0 && countMinus <= 1 && afterDigitMinus >= 0)
  58. {
  59. integer = int.Parse(input);
  60. if (position == 0 && beforeDigitMinus == 1)
  61. {
  62. dataType = "string";
  63. }
  64. else if (integer % 1 == 0)
  65. {
  66. dataType = "integer";
  67. break;
  68. }
  69. }
  70. }
  71. else
  72. {
  73. countAllSymbol++;
  74. countSymbol++;
  75. charSymbol = item;
  76. if (charSymbol == '.')
  77. {
  78. countPoint++;
  79. }
  80. else if (charSymbol == '-' && countDigit >= 0)
  81. {
  82. if (afterPoint >= 1)
  83. {
  84. countMinus++;
  85. }
  86. else if (countDigit >= 1)
  87. {
  88. afterDigitMinus++;
  89. }
  90. countMinus++;
  91. }
  92. else
  93. {
  94. countOther++;
  95. }
  96. if (countSymbol == 1)
  97. {
  98. firstSymbol = charSymbol;
  99. }
  100. else if (countSymbol == 2)
  101. {
  102. secondSymbol = charSymbol;
  103. }
  104.  
  105. }
  106. if (input.Length == countAllSymbol && countPoint == 1 && input.Length > 1 && afterDigitMinus == 0 && countAllSymbol != countSymbol)
  107. {
  108. if ((beforePoint >= 0 || afterPoint >= 0) && countMinus <= 1 && countOther == 0 && (firstSymbol == '-' || secondSymbol == '.') && countDigit > 0)
  109. {
  110. if (position == 0)
  111. {
  112. dataType = "string";
  113. }
  114. else
  115. {
  116. dataType = "floating point";
  117. }
  118. }
  119. else
  120. {
  121. if (firstSymbol == '.' && secondSymbol != '-' && countSymbol > 2 && countOther == 0)
  122. {
  123. dataType = "floating point";
  124. }
  125. else
  126. {
  127. if (firstSymbol == '.' && countSymbol == 1)
  128. {
  129. dataType = "floating point";
  130. }
  131. else
  132. {
  133. dataType = "string";
  134. }
  135. }
  136. }
  137. }
  138. else if (input.Length == 1 && Char.IsDigit(item) != true)
  139. {
  140. dataType = "character";
  141. }
  142. else if (input == "true" || input == "false")
  143. {
  144. dataType = "boolean";
  145. }
  146. else if (input.Length > 1 && input.Length == countAllSymbol || afterDigitMinus >= 1)
  147. {
  148. dataType = "string";
  149. }
  150. }
  151. beforePoint = 0;
  152. afterPoint = 0;
  153. beforeDigitMinus = 0;
  154. afterDigitMinus = 0;
  155. charSymbol = ' ';
  156. firstSymbol = ' ';
  157. secondSymbol = ' ';
  158. countPoint = 0;
  159. countMinus = 0;
  160. countOther = 0;
  161. countAllSymbol = 0;
  162. countSymbol = 0;
  163. countDigit = 0;
  164. Console.WriteLine($"{input} is {dataType} type");
  165. input = Console.ReadLine();
  166. }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement