Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HomeWork
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- string text = "(()(()))";
- char openBracket = '(';
- int currentDepth = 0;
- int maxDepth = 0;
- foreach (var symbol in text)
- {
- if (symbol == openBracket)
- {
- currentDepth++;
- if (maxDepth < currentDepth)
- maxDepth = currentDepth;
- }
- else
- {
- currentDepth--;
- }
- }
- if (currentDepth == 0)
- {
- Console.WriteLine("Правильное скобочное выражение.");
- Console.WriteLine("Глубина вложенности скобок: " + maxDepth);
- }
- else
- {
- Console.WriteLine("Неправильное скобочное выражение.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement