Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- int currentDepth = 0;
- int maximumDepth = 0;
- char openingBracket = '(';
- char closureBracket = ')';
- string userInput;
- Console.WriteLine("Здравствуйте. Введите символы скобочек, желательно правильно," +
- "чтобы показать что код сработает верно! Спасибо))");
- userInput = Console.ReadLine();
- for (int i = 0; i < userInput.Length; i++)
- {
- if (userInput[i] == openingBracket)
- {
- currentDepth++;
- if (currentDepth > maximumDepth)
- {
- maximumDepth = currentDepth;
- }
- }
- else if (userInput[i] == closureBracket)
- {
- currentDepth--;
- if (currentDepth < 0)
- {
- break;
- }
- }
- }
- if (maximumDepth <= 0 || currentDepth < 0)
- {
- Console.WriteLine("Что-то пошло уж совсем не так...");
- }
- else if (currentDepth == 0 || maximumDepth != 0)
- {
- Console.WriteLine($"Скобочное выражение верно! Глубина скобок - {maximumDepth}");
- }
- else
- {
- Console.WriteLine("Скобочное выражение неверно!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement