Advertisement
Rodunskiy

Untitled

Apr 18th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. char symbol1 = '(';
  2. char symbol2 = ')';
  3. string symbolLine = "( и )";
  4. int maximumDepth = 0;
  5. int symbolsCount = 0;
  6.  
  7. for (int i = 0; i < symbolLine.Length; i++)
  8. {
  9.     if (symbolLine[i] == symbol1)
  10.     {
  11.         symbolsCount++;
  12.  
  13.         if (symbolsCount > maximumDepth)
  14.         {
  15.             maximumDepth = symbolsCount;
  16.         }
  17.     }
  18.     else if (symbolLine[i] == symbol2)
  19.     {
  20.         symbolsCount--;
  21.     }
  22. }
  23.  
  24. if (symbolsCount != 0)
  25. {
  26.     Console.WriteLine("Не корректная запись.");
  27. }
  28. else
  29. {
  30.     Console.WriteLine($"Строка корректная. Максимальная глубина - {maximumDepth}.");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement