Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Velsimir/e73b171044a65505412a7c0343f2c4ae to your computer and use it in GitHub Desktop.
Save Velsimir/e73b171044a65505412a7c0343f2c4ae to your computer and use it in GitHub Desktop.
using System;
using System.Security.Policy;
using System.Threading;
namespace iJunior
{
class MainClass
{
public static void Main(string[] args)
{
int numberOfBrackets = 0;
string userInput;
bool expressionIsCorrect = true;
char previousSymbol = ' ';
int streak = 1;
int minStreak = 1;
int maxStreak = 1;
Console.Write("Введите случайное количество симовлов ( ) - ");
userInput = Console.ReadLine();
int lenghtInput = userInput.Length - 1;
if (userInput[0] == ')' || userInput[lenghtInput] == '(')
{
expressionIsCorrect = false;
}
else
{
foreach (var symbol in userInput)
{
if (symbol == '(')
numberOfBrackets++;
else
numberOfBrackets--;
if (numberOfBrackets < 0)
{
Console.WriteLine("Закрывающих скобок больше, чем открывающих");
expressionIsCorrect = false;
break;
}
if (symbol == previousSymbol)
streak++;
else
streak = minStreak;
if (streak > maxStreak)
maxStreak = streak;
previousSymbol = symbol;
}
}
if (expressionIsCorrect)
{
Console.WriteLine($"Скобочное выражение является корректным" +
$"\nГлубина скобочного выражения = {maxStreak}");
}
else
{
Console.WriteLine("Скобочное выражение является не корректным");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment