Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework3_9
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string symbols = "((()((()))()))";
- int depth = 0;
- int maxDepth = 0;
- char openBracket = '(';
- char closeBracket = ')';
- Console.WriteLine(symbols);
- for (int i = 0; i < symbols.Length; i++)
- {
- if (symbols[i] == openBracket)
- {
- depth++;
- maxDepth = Math.Max(maxDepth, depth);
- }
- else if (symbols[i] == closeBracket)
- {
- depth--;
- }
- if (depth < 0)
- {
- break;
- }
- }
- if (depth == 0)
- {
- Console.WriteLine($"Cтрока корректная и максимум глубины равняется {maxDepth}.");
- }
- else
- {
- Console.WriteLine("Строка некорректная.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement