Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- static void Main(string[] args)
- {
- char openParenthesis = '(';
- char closedParenthesis = ')';
- int countParenthesis = 0;
- int maxCountParenthesis = 0;
- Console.Write($"Введите строку из скобок '{openParenthesis}' и '{closedParenthesis}' - ");
- string userInput = Console.ReadLine();
- foreach (char parenthesis in userInput)
- {
- if (parenthesis == openParenthesis)
- {
- countParenthesis++;
- if (countParenthesis > maxCountParenthesis)
- maxCountParenthesis = countParenthesis;
- }
- else
- {
- countParenthesis--;
- if (countParenthesis < 0)
- break;
- }
- }
- if (countParenthesis == 0)
- {
- Console.WriteLine($"строка корректная и максимум глубины равняется {maxCountParenthesis}");
- }
- else
- {
- Console.WriteLine("Некорректная строка.");
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment