Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _01DataTypeFinder
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- int position = 0;
- string dataType = "";
- int countAllSymbol = 0;
- int countSymbol = 0;
- int countPoint = 0;
- int countMinus = 0;
- int countOther = 0;
- int countDigit = 0;
- char charSymbol = ' ';
- int beforePoint = 0;
- int afterPoint = 0;
- int beforeDigitMinus = 0;
- int afterDigitMinus = 0;
- char firstSymbol = ' ';
- char secondSymbol = ' ';
- int integer = 0;
- double floating = 0.0;
- while (input != "END")
- {
- foreach (var item in input)
- {
- if (Char.IsDigit(item) == true)
- {
- countDigit++;
- position = (int)Char.GetNumericValue(item);
- countAllSymbol++;
- if (countPoint == 0 && countAllSymbol > 0)
- {
- beforePoint++;
- }
- else if (charSymbol == '.')
- {
- afterPoint++;
- }
- if (countMinus == 1 && countSymbol == 1)
- {
- beforeDigitMinus++;
- }
- else if (charSymbol == '-')
- {
- afterDigitMinus++;
- }
- if (input.Length == countAllSymbol && countOther == 0 && countPoint == 0 && countMinus <= 1 && afterDigitMinus >= 0)
- {
- integer = int.Parse(input);
- if (position == 0 && beforeDigitMinus == 1)
- {
- dataType = "string";
- }
- else if (integer % 1 == 0)
- {
- dataType = "integer";
- break;
- }
- }
- }
- else
- {
- countAllSymbol++;
- countSymbol++;
- charSymbol = item;
- if (charSymbol == '.')
- {
- countPoint++;
- }
- else if (charSymbol == '-' && countDigit >= 0)
- {
- if (afterPoint >= 1)
- {
- countMinus++;
- }
- else if (countDigit >= 1)
- {
- afterDigitMinus++;
- }
- countMinus++;
- }
- else
- {
- countOther++;
- }
- if (countSymbol == 1)
- {
- firstSymbol = charSymbol;
- }
- else if (countSymbol == 2)
- {
- secondSymbol = charSymbol;
- }
- }
- if (input.Length == countAllSymbol && countPoint == 1 && input.Length > 1 && afterDigitMinus == 0 && countAllSymbol != countSymbol)
- {
- if ((beforePoint >= 0 || afterPoint >= 0) && countMinus <= 1 && countOther == 0 && (firstSymbol == '-' || secondSymbol == '.') && countDigit > 0)
- {
- if (position == 0)
- {
- dataType = "string";
- }
- else
- {
- dataType = "floating point";
- }
- }
- else
- {
- if (firstSymbol == '.' && secondSymbol != '-' && countSymbol > 2 && countOther == 0)
- {
- dataType = "floating point";
- }
- else
- {
- if (firstSymbol == '.' && countSymbol == 1)
- {
- dataType = "floating point";
- }
- else
- {
- dataType = "string";
- }
- }
- }
- }
- else if (input.Length == 1 && Char.IsDigit(item) != true)
- {
- dataType = "character";
- }
- else if (input == "true" || input == "false")
- {
- dataType = "boolean";
- }
- else if (input.Length > 1 && input.Length == countAllSymbol || afterDigitMinus >= 1)
- {
- dataType = "string";
- }
- }
- beforePoint = 0;
- afterPoint = 0;
- beforeDigitMinus = 0;
- afterDigitMinus = 0;
- charSymbol = ' ';
- firstSymbol = ' ';
- secondSymbol = ' ';
- countPoint = 0;
- countMinus = 0;
- countOther = 0;
- countAllSymbol = 0;
- countSymbol = 0;
- countDigit = 0;
- Console.WriteLine($"{input} is {dataType} type");
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement