Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp18
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string parentheses = "(((()))())";
- char leftParenhesis = '(';
- char rightParenthesis = ')';
- int currentDepth = 0;
- int maximumDepth = 0;
- int controlNumber = 0;
- for (int i = 0; i < parentheses.Length; i++)
- {
- if (parentheses[i] == leftParenhesis)
- {
- currentDepth++;
- }
- else if (parentheses[i] == rightParenthesis)
- {
- currentDepth--;
- }
- if (currentDepth > maximumDepth)
- {
- maximumDepth = currentDepth;
- }
- if(currentDepth<controlNumber)
- {
- break;
- }
- }
- if (currentDepth == controlNumber)
- {
- Console.WriteLine($"Корректно.Максимальная вложенность {maximumDepth}");
- }
- else
- {
- Console.WriteLine("Не корректно.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment