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 CSTemp
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string text = "";
- int deepCount = 0;
- int correctness = 0;
- char leftParenthesis = '(';
- Console.Write("Введите скобочное выражение: ");
- text = Console.ReadLine();
- foreach (var symbol in text)
- {
- if (symbol == leftParenthesis)
- {
- correctness++;
- }
- else
- {
- correctness--;
- }
- if( correctness > deepCount)
- {
- deepCount = correctness;
- }
- else if(correctness < 0)
- {
- Console.WriteLine("Выражение неверно");
- Console.ReadKey();
- return;
- }
- }
- Console.WriteLine($"Глубина выражения - {deepCount}");
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment