Skip to content

Instantly share code, notes, and snippets.

@KristiBu888
Last active June 8, 2025 12:49
Show Gist options
  • Save KristiBu888/bbd2901051457ef982118a1179cdda3d to your computer and use it in GitHub Desktop.
Save KristiBu888/bbd2901051457ef982118a1179cdda3d to your computer and use it in GitHub Desktop.
Рассолова ДЗ: Массивы.Скобочное выражение
using System;
namespace Project_1
{
internal class Program
{
static void Main(string[] args)
{
string brackets = "(())";
char openBrackets = '(';
char closeBrackets = ')';
int depth = 0;
int maxDepth = 0;
bool isCorrect = true;
for (int i = 0; i < brackets.Length; i++)
{
if (brackets[i] == openBrackets)
{
depth++;
}
else if (brackets[i] == closeBrackets)
{
depth--;
}
if (depth < 0)
{
isCorrect = false;
break;
}
if (depth > maxDepth)
{
maxDepth = depth;
}
}
if (isCorrect && depth == 0)
{
Console.WriteLine($"{brackets} - является корректным скобочным выражением." +
$"\nМаксимум глубины = {maxDepth}.");
}
else
{
Console.WriteLine($"{brackets} - некорректное скобочное выражение.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment