Last active
July 6, 2025 12:20
-
-
Save ConorMkGrEGOR/f4a7d944c3de7e30213a1f1a17d6a9cc 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 CSLight | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
const char OpenBracket = '('; | |
const char ClosedBracket = ')'; | |
Console.WriteLine("Введите скобочное выражение:"); | |
string brackets = Console.ReadLine(); | |
int depthAttachment = 0; | |
int lastIndex = brackets.Length - 1; | |
int maxDepth = 1; | |
bool isCorrect = true; | |
for (int i = 0; i < brackets.Length; i++) | |
{ | |
if (brackets[i] != OpenBracket && brackets[i] != ClosedBracket) | |
{ | |
Console.WriteLine("Вы ввели некорректные данные."); | |
isCorrect = false; | |
maxDepth = 0; | |
break; | |
} | |
if (brackets[i] == OpenBracket) | |
{ | |
depthAttachment++; | |
} | |
else | |
{ | |
depthAttachment--; | |
} | |
if (depthAttachment < 0) | |
{ | |
isCorrect = false; | |
break; | |
} | |
if (depthAttachment > maxDepth) | |
{ | |
maxDepth = depthAttachment; | |
} | |
} | |
Console.WriteLine($"Выражение верно ? - {isCorrect}. " + | |
$"Глубина вложенности - {maxDepth}."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment