Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HW
- {
- class Program
- {
- static void Main(string[] args)
- {
- string brackets;
- int depthBrackets = 0;
- bool correctBrackets = true;
- int correctnessCheck = 0;
- Console.Write("Введите скобочное выражение: ");
- brackets = Console.ReadLine();
- foreach (var bracket in brackets)
- {
- if (bracket == '(')
- {
- correctnessCheck++;
- }
- if (bracket == ')')
- {
- correctnessCheck--;
- }
- if (depthBrackets < correctnessCheck)
- {
- depthBrackets++;
- }
- if (correctnessCheck < 0)
- {
- correctBrackets = false;
- break;
- }
- }
- if(correctnessCheck > 0)
- {
- correctBrackets = false;
- }
- Console.WriteLine("Корректность выражения = " + correctBrackets);
- Console.WriteLine("Максимальная глубина скобок = " + depthBrackets);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement