Skip to content

Instantly share code, notes, and snippets.

@VladimirYus
Last active December 12, 2025 10:14
Show Gist options
  • Select an option

  • Save VladimirYus/b0dac723d37fd864f4e38bd3445bd6e8 to your computer and use it in GitHub Desktop.

Select an option

Save VladimirYus/b0dac723d37fd864f4e38bd3445bd6e8 to your computer and use it in GitHub Desktop.
ParentheticalExpression
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