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 depth = 0;
- int maximumDepth = 0;
- int minimuDepth = 0;
- int controlNumber = 0;
- for (int i = 0; i < parentheses.Length; i++)
- {
- if (parentheses[i] == leftParenhesis)
- {
- depth++;
- }
- else if (parentheses[i] == rightParenthesis)
- {
- depth--;
- }
- if (depth > maximumDepth)
- {
- maximumDepth = depth;
- }
- if(depth< minimuDepth)
- {
- minimuDepth=depth;
- }
- }
- if (depth == controlNumber && minimuDepth == controlNumber)
- {
- Console.WriteLine("Корректно.");
- }
- else
- {
- Console.WriteLine("Не корректно.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment