Advertisement
Askor

NewHw19

Apr 14th, 2022
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string line = "( (()) ((())) )";
  8.         int currentDeep = 0;
  9.         int maxDeep = 0;
  10.         int lineCharCount = line.Length;
  11.  
  12.         for (int i = 0; i < lineCharCount; i++)
  13.         {
  14.             if (line[i] == '(')
  15.             {
  16.                 currentDeep++;
  17.  
  18.                 if (currentDeep > maxDeep)
  19.                 {
  20.                     maxDeep = currentDeep;
  21.                 }
  22.             }
  23.             else if (line[i] == ')')
  24.             {
  25.                 if (currentDeep > 0)
  26.                 {
  27.                     currentDeep--;
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine("error");
  32.                 }
  33.             }
  34.         }
  35.  
  36.         if(currentDeep == 0)
  37.         {
  38.             Console.WriteLine($"Deep: {maxDeep}");
  39.         }
  40.        
  41.         Console.ReadKey();
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement