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 Home_Work
- {
- class Program
- {
- static void Main()
- {
- string userInput;
- int depth = 0;
- int maxDepth = depth;
- bool isCorrect = true;
- Console.Write("Введите скобочное выражение: ");
- userInput = Console.ReadLine();
- foreach (char symbol in userInput)
- {
- switch (symbol)
- {
- case '(':
- depth++;
- if (depth > maxDepth)
- maxDepth = depth;
- break;
- case ')':
- depth--;
- if (depth < 0)
- isCorrect = false;
- break;
- default:
- isCorrect = false;
- break;
- }
- }
- if (isCorrect && depth == 0)
- Console.WriteLine("Скобочное выражение корректно. Максимальная глубина: " + maxDepth);
- else
- Console.WriteLine("Скобочное выражение не корректно. Возможная глубина " + maxDepth);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment