Created
July 5, 2024 19:49
-
-
Save MagSosiq/09b9afb1751f763cf90fb108aad28649 to your computer and use it in GitHub Desktop.
This file contains 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; | |
using System.Text; | |
namespace HW1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
string userInput; | |
char fistSymbol = '('; | |
char secondSymbol = ')'; | |
int symbolsCount = 0; | |
int countMaxDepth = 0; | |
Console.WriteLine("Программа определяющая корректность и глубину строки:"); | |
userInput = Console.ReadLine(); | |
for (int i = 0; i < userInput.Length; i++) | |
{ | |
if (userInput[i] == fistSymbol) | |
{ | |
symbolsCount++; | |
if (symbolsCount > countMaxDepth) | |
{ | |
countMaxDepth = symbolsCount; | |
} | |
} | |
else if (userInput[i] == secondSymbol) | |
{ | |
symbolsCount--; | |
if (symbolsCount < 0) | |
{ | |
break; | |
} | |
} | |
} | |
if (symbolsCount != 0) | |
{ | |
Console.WriteLine("Строка не корректная."); | |
} | |
else | |
{ | |
Console.WriteLine($"Строка корректная. Максимальная глубина - {countMaxDepth}."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment