Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace stringWithBasket
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string bracketsString = "(()(()))";
- int parenthesisDepth = 0;
- int currentDepth = 0;
- int divisorOfNaturalNumber = 2;
- char openBrecket = '(';
- char closeBrecket = ')';
- if (bracketsString.Length % divisorOfNaturalNumber != 0 || bracketsString[0] == closeBrecket || bracketsString[bracketsString.Length - 1] == openBrecket)
- {
- Console.WriteLine("Не корректная строка.");
- }
- else
- {
- foreach (char bracket in bracketsString)
- {
- if (bracket == openBrecket)
- {
- currentDepth++;
- }
- else
- {
- currentDepth--;
- }
- if (currentDepth < 0)
- {
- break;
- }
- if (currentDepth > parenthesisDepth)
- {
- parenthesisDepth = currentDepth;
- }
- }
- if (currentDepth != 0)
- {
- Console.WriteLine("Не корректная строка.");
- }
- else
- {
- Console.WriteLine($"{bracketsString} - строка корректная и максимум глубины равняется {parenthesisDepth}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement