Skip to content

Instantly share code, notes, and snippets.

@MagSosiq
Created July 5, 2024 19:49
Show Gist options
  • Save MagSosiq/09b9afb1751f763cf90fb108aad28649 to your computer and use it in GitHub Desktop.
Save MagSosiq/09b9afb1751f763cf90fb108aad28649 to your computer and use it in GitHub Desktop.
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