Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int counterMaxDeep = 0;
- int maxDeep = 0;
- char symbol = '(';
- string userInput;
- Console.Write("Введите скобочное выражение: ");
- userInput = Console.ReadLine();
- for (int i = 0; i < userInput.Length; i++)
- {
- if (userInput[i] == symbol)
- {
- counterMaxDeep++;
- if (counterMaxDeep > maxDeep)
- {
- maxDeep = counterMaxDeep;
- }
- }
- else
- {
- counterMaxDeep--;
- if (counterMaxDeep < 0)
- {
- break;
- }
- }
- }
- if (counterMaxDeep == 0)
- {
- Console.WriteLine("\nВерное выражение.");
- Console.WriteLine($"Максимальная глубина: {maxDeep}\n");
- }
- else
- {
- Console.WriteLine("\nНеверное выражение!\n");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement