Advertisement
JulianJulianov

01DataTypeFinder without 4. & .4 is string

Oct 10th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 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. string dataType = "";
  16. int countSymbol = 0;
  17. int countPoint = 0;
  18. int countMinus = 0;
  19. int countOther = 0;
  20. char charSymbol = ' ';
  21. int beforePoint = 0;
  22. int afterPoint = 0;
  23.  
  24. while (input != "END")
  25. {
  26. foreach (var item in input)
  27. {
  28. if (Char.IsDigit(item) == true)
  29. {
  30. int position = (int)Char.GetNumericValue(item);
  31. countSymbol++;
  32. if (charSymbol == ' ' || charSymbol == '-' && countPoint == 0)
  33. {
  34. beforePoint++;
  35. }
  36. else if (charSymbol == '.')
  37. {
  38. afterPoint++;
  39. }
  40. if (input.Length == countSymbol && countOther == 0 && countPoint == 0 && countMinus <= 1)
  41. {
  42. dataType = "integer";
  43. break;
  44. }
  45. }
  46. else
  47. {
  48. countSymbol++;
  49. charSymbol = item;
  50. if (charSymbol == '.')
  51. {
  52. countPoint++;
  53. }
  54. else if (charSymbol == '-')
  55. {
  56. if (afterPoint >= 1)
  57. {
  58. countMinus++;
  59. }
  60. countMinus++;
  61. }
  62. else
  63. {
  64. countOther++;
  65. }
  66. if (input.Length == countSymbol && countPoint == 1 && input.Length > 1)
  67. {
  68. if (beforePoint > 0 && afterPoint > 0 && countMinus <= 1)
  69. {
  70. dataType = "floating point";
  71. }
  72. else
  73. {
  74. dataType = "string";
  75. }
  76. }
  77. else if (input.Length == 1 && Char.IsDigit(item) != true)
  78. {
  79. dataType = "character";
  80. }
  81. else if (input == "true" || input == "false")
  82. {
  83. dataType = "boolean";
  84. }
  85. else if (input.Length > 1 && input.Length == countSymbol)
  86. {
  87. dataType = "string";
  88. }
  89. }
  90. beforePoint = 0;
  91. afterPoint = 0;
  92. charSymbol = ' ';
  93. countPoint = 0;
  94. countMinus = 0;
  95. countOther = 0;
  96. countSymbol = 0;
  97. Console.WriteLine($"{input} is {dataType} type");
  98. input = Console.ReadLine();
  99. }
  100. }
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement