Last active
June 8, 2025 12:49
-
-
Save KristiBu888/bbd2901051457ef982118a1179cdda3d to your computer and use it in GitHub Desktop.
Рассолова ДЗ: Массивы.Скобочное выражение
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 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