Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string brakets = "()";
- char openedBraket = '(';
- char closedBraket = ')';
- int maxDeep = 0;
- int currentDeep = 0;
- int half = 2;
- if (brakets.Length % half == 0)
- {
- for (int i = 0; i < brakets.Length; i++)
- {
- if (brakets[i] == openedBraket)
- {
- currentDeep++;
- if (currentDeep > maxDeep)
- {
- maxDeep = currentDeep;
- }
- }
- else if (brakets[i] == closedBraket)
- {
- currentDeep--;
- if(currentDeep < 0)
- {
- break;
- }
- }
- }
- if (currentDeep != 0)
- {
- Console.WriteLine("Строка не корректна");
- }
- else
- {
- Console.WriteLine($"Строка корректна. Глубина {maxDeep}");
- }
- }
- else
- {
- Console.WriteLine("Строка не корректна");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement