Advertisement
MyOnAsSalat

Untitled

Mar 10th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2.     class Program
  3.     {
  4.         enum identificator
  5.         {
  6.             Simple_Identificator,
  7.             Operation_All,
  8.             Identificator,
  9.             Error
  10.         }
  11.         static bool symbol(char a)
  12.         {
  13.             return a >= 'A' && a <= 'Z';
  14.         }
  15.  
  16.         static bool operation(char a)
  17.         {
  18.             return a == '+' || a == '-' || a == '/' || a == '*';
  19.         }
  20.  
  21.         static identificator recursion(string a, int pos = 0)
  22.         {
  23.             if (a.Length != pos)
  24.             {
  25.                 if (pos % 2 == 0) return symbol(a[pos]) ? recursion(a, pos + 1) : identificator.Error;
  26.                 return operation(a[pos]) ? recursion(a, pos + 1) : identificator.Error;                    
  27.             }
  28.             return identificator.Simple_Identificator;
  29.         }
  30.  
  31.         static identificator check(string a)
  32.         {
  33.             if (a.Length == 1)
  34.             {
  35.                 if (operation(a[0])) return identificator.Operation_All;
  36.                 if (symbol(a[0])) return identificator.Identificator;
  37.             }
  38.             if (a.Length % 2 == 0) return identificator.Error;
  39.             return recursion(a);
  40.         }
  41.  
  42.         public static void Main()
  43.         {
  44.             circle();
  45.         }
  46.         static void circle()
  47.         {
  48.             identificator ident = check(Console.ReadLine());
  49.             if (ident == identificator.Simple_Identificator) Console.WriteLine("Statement");
  50.             else if (ident == identificator.Identificator) Console.WriteLine("Identificator");
  51.             else if (ident == identificator.Operation_All) Console.WriteLine("Operation");          
  52.             else Console.WriteLine("Invalid input");      
  53.             circle();
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement