Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main(string[] args)
- {
- char bracketStart = '(';
- char bracketEnd = ')';
- Console.Write("Input Brackets : ");
- string brackets = Console.ReadLine();
- int bracketsDepth = 0;
- int bracketsDepthMax = 0;
- bool isWrong = false;
- foreach(char bracket in brackets)
- {
- if(bracket == bracketStart)
- {
- ++bracketsDepth;
- }
- else if(bracket == bracketEnd)
- {
- if(bracketsDepth > bracketsDepthMax)
- bracketsDepthMax = bracketsDepth;
- --bracketsDepth;
- }
- if(bracketsDepth < 0)
- {
- isWrong = true;
- break;
- }
- }
- if(isWrong)
- Console.WriteLine("String with brackets is incorrect.");
- else
- Console.WriteLine("String with brackets is correct. Max depth of brackets is : " + bracketsDepthMax);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement