kwest87

Untitled

Dec 29th, 2023
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp18
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string parentheses = "(()(()))";
  10.             char leftParenhesis = '(';
  11.             char rightParenthesis = ')';
  12.             int depth = 0;
  13.             int maximumDepth = 0;
  14.             int minimuDepth = 0;
  15.             int controlNumber = 0;
  16.  
  17.             for (int i = 0; i < parentheses.Length; i++)
  18.             {
  19.                 if (parentheses[i] == leftParenhesis)
  20.                 {
  21.                     depth++;
  22.                 }
  23.                 else if (parentheses[i] == rightParenthesis)
  24.                 {
  25.                     depth--;
  26.                 }
  27.  
  28.                 if (depth > maximumDepth)
  29.                 {
  30.                     maximumDepth = depth;
  31.                 }
  32.  
  33.                 if(depth< minimuDepth)
  34.                 {
  35.                     minimuDepth=depth;
  36.                 }
  37.             }
  38.  
  39.             if (depth == controlNumber && minimuDepth == controlNumber)
  40.             {
  41.                 Console.WriteLine("Корректно.");
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine("Не корректно.");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment