Last active
October 18, 2022 12:38
-
-
Save Velsimir/e73b171044a65505412a7c0343f2c4ae 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.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