lightb01

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

Jun 29th, 2022 (edited)
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 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 CSTemp
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = "";
  14.             int deepCount = 0;
  15.             int correctness = 0;
  16.             char leftParenthesis = '(';
  17.  
  18.             Console.Write("Введите скобочное выражение: ");
  19.             text = Console.ReadLine();
  20.  
  21.             foreach (var symbol in text)
  22.             {
  23.                 if (symbol == leftParenthesis)
  24.                 {
  25.                     correctness++;
  26.                 }
  27.                 else
  28.                 {
  29.                     correctness--;
  30.                 }
  31.  
  32.                 if( correctness > deepCount)
  33.                 {
  34.                     deepCount = correctness;
  35.                 }
  36.                 else  if(correctness < 0)
  37.                 {
  38.                     Console.WriteLine("Выражение неверно");
  39.                     Console.ReadKey();
  40.                     return;
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine($"Глубина выражения - {deepCount}");
  45.             Console.ReadKey();
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment