Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- string line = "( (()) ((())) )";
- int currentDeep = 0;
- int maxDeep = 0;
- int lineCharCount = line.Length;
- for (int i = 0; i < lineCharCount; i++)
- {
- if (line[i] == '(')
- {
- currentDeep++;
- if (currentDeep > maxDeep)
- {
- maxDeep = currentDeep;
- }
- }
- else if (line[i] == ')')
- {
- if (currentDeep > 0)
- {
- currentDeep--;
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- }
- if(currentDeep == 0)
- {
- Console.WriteLine($"Deep: {maxDeep}");
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement