Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int currentDepth = 0;
- int maxDepth = 0;
- char leftRoundBracket = '(';
- char rightRoundBracket = ')';
- Console.WriteLine($"Введите символы {leftRoundBracket} и {rightRoundBracket}");
- string inputMessage = Console.ReadLine();
- foreach (char symbol in inputMessage)
- {
- if (symbol == leftRoundBracket)
- {
- currentDepth++;
- }
- else if (symbol == rightRoundBracket)
- {
- currentDepth--;
- }
- if (currentDepth < 0)
- {
- break;
- }
- if (maxDepth < currentDepth)
- {
- maxDepth = currentDepth;
- }
- }
- if (currentDepth == 0)
- {
- Console.WriteLine($"Строка корректная:{inputMessage}\nМаксимум глубина равняется: {(maxDepth)}");
- }
- else
- {
- Console.WriteLine($"Ошибка! Не верная строка: {inputMessage}");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement