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