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();
- string dataType = "";
- int countSymbol = 0;
- int countPoint = 0;
- int countMinus = 0;
- int countOther = 0;
- char charSymbol = ' ';
- int beforePoint = 0;
- int afterPoint = 0;
- while (input != "END")
- {
- foreach (var item in input)
- {
- if (Char.IsDigit(item) == true)
- {
- int position = (int)Char.GetNumericValue(item);
- countSymbol++;
- if (charSymbol == ' ' || charSymbol == '-' && countPoint == 0)
- {
- beforePoint++;
- }
- else if (charSymbol == '.')
- {
- afterPoint++;
- }
- if (input.Length == countSymbol && countOther == 0 && countPoint == 0 && countMinus <= 1)
- {
- dataType = "integer";
- break;
- }
- }
- else
- {
- countSymbol++;
- charSymbol = item;
- if (charSymbol == '.')
- {
- countPoint++;
- }
- else if (charSymbol == '-')
- {
- if (afterPoint >= 1)
- {
- countMinus++;
- }
- countMinus++;
- }
- else
- {
- countOther++;
- }
- if (input.Length == countSymbol && countPoint == 1 && input.Length > 1)
- {
- if (beforePoint > 0 && afterPoint > 0 && countMinus <= 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 == countSymbol)
- {
- dataType = "string";
- }
- }
- beforePoint = 0;
- afterPoint = 0;
- charSymbol = ' ';
- countPoint = 0;
- countMinus = 0;
- countOther = 0;
- countSymbol = 0;
- Console.WriteLine($"{input} is {dataType} type");
- input = Console.ReadLine();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement