Advertisement
junniorrkaa

Скобочное выражение

Oct 25th, 2024 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int counterMaxDeep = 0;
  10.             int maxDeep = 0;
  11.  
  12.             char symbol = '(';
  13.  
  14.             string userInput;
  15.  
  16.             Console.Write("Введите скобочное выражение: ");
  17.  
  18.             userInput = Console.ReadLine();
  19.  
  20.             for (int i = 0; i < userInput.Length; i++)
  21.             {
  22.                 if (userInput[i] == symbol)
  23.                 {
  24.                     counterMaxDeep++;
  25.  
  26.                     if (counterMaxDeep > maxDeep)
  27.                     {
  28.                         maxDeep = counterMaxDeep;
  29.                     }
  30.                 }
  31.                 else
  32.                 {
  33.                     counterMaxDeep--;
  34.  
  35.                     if (counterMaxDeep < 0)
  36.                     {
  37.                         break;
  38.                     }
  39.                 }
  40.             }
  41.  
  42.             if (counterMaxDeep == 0)
  43.             {
  44.                 Console.WriteLine("\nВерное выражение.");
  45.                 Console.WriteLine($"Максимальная глубина: {maxDeep}\n");
  46.             }
  47.             else
  48.             {
  49.                 Console.WriteLine("\nНеверное выражение!\n");
  50.             }
  51.  
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement