Last active
May 27, 2025 14:43
-
-
Save hidden-pool/140afc4ef1f2b2d575a015e03d367219 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 Variables | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string stringChars = "(()"; | |
char openBracket = '('; | |
char closBracket = ')'; | |
int currentDepth = 0; | |
int maximumDepth = 0; | |
bool isValid = true; | |
foreach (char symbol in stringChars) | |
{ | |
if (symbol == openBracket) | |
{ | |
currentDepth++; | |
maximumDepth = Math.Max(maximumDepth, currentDepth); | |
} | |
else if (symbol == closBracket) | |
{ | |
if (currentDepth == 0) | |
{ | |
isValid = false; | |
break; | |
} | |
currentDepth--; | |
} | |
} | |
Console.WriteLine(isValid ? $"Глубина: {maximumDepth}" : "Некорректная строка"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment