Last active
December 12, 2025 10:14
-
-
Save VladimirYus/b0dac723d37fd864f4e38bd3445bd6e8 to your computer and use it in GitHub Desktop.
ParentheticalExpression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace ParentheticalExpression | |
| { | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| int currentDepth = 0; | |
| int maxDepth = 0; | |
| char bracketOpen = '('; | |
| char bracketClose = ')'; | |
| Console.Write($"Введите строку из символов {bracketOpen} и {bracketClose}: "); | |
| string userInputBracket = Console.ReadLine(); | |
| foreach (char bracket in userInputBracket) | |
| { | |
| if (bracket == bracketOpen) | |
| { | |
| currentDepth++; | |
| if (currentDepth > maxDepth) | |
| { | |
| maxDepth = currentDepth; | |
| } | |
| } | |
| else if (bracket == bracketClose) | |
| { | |
| currentDepth--; | |
| if (currentDepth < 0) | |
| { | |
| break; | |
| } | |
| } | |
| } | |
| if (currentDepth == 0) | |
| { | |
| Console.WriteLine($"Строка корректная. Максимум глубины является: {maxDepth}"); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Строка некорректная."); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment