Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lectures
- {
- class Program
- {
- static void Main()
- {
- string staples = "((())()())()";
- int currentDepth = 0;
- int maximumInvestment = 0;
- bool isWork = false;
- foreach (var symbol in staples)
- {
- switch (symbol)
- {
- case '(':
- currentDepth++;
- if (currentDepth > maximumInvestment)
- {
- maximumInvestment = currentDepth;
- }
- break;
- case ')':
- if (currentDepth > 0)
- {
- currentDepth--;
- }
- else
- {
- isWork = true;
- }
- break;
- }
- }
- if (!isWork)
- {
- Console.WriteLine($"Строка корректна, максимальная глубина равна {maximumInvestment}.");
- }
- else
- {
- Console.WriteLine($"Некорректная строка, максимальная глубина равна {maximumInvestment}.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment