Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HomeWork
- {
- class Program
- {
- static void Main(string[] args)
- {
- int depth = 0;
- int counterDepth = 0;
- string strUser = "";
- char[] strUserArray;
- Console.WriteLine("Введите строку для разбора.");
- strUser = Console.ReadLine();
- strUserArray = strUser.ToCharArray();
- for (int i = 0; i < strUserArray.Length; i++)
- {
- if (strUserArray[i] == '(')
- depth++;
- else if ((strUserArray[i] == ')') && (depth > 0))
- {
- depth--;
- counterDepth++;
- }
- else if (strUserArray[i] == ')')
- {
- if (i != strUserArray.Length - 1 && strUserArray[i + 1] != '(')
- counterDepth++;
- depth--;
- }
- else if (strUserArray[i] != ')' && ((depth < 0) || depth > 0))
- {
- Console.WriteLine("Строка не верная!");
- break;
- }
- }
- if (depth == 0)
- Console.WriteLine($"Строка не верная!");
- else
- Console.WriteLine($"Глубина строки = {counterDepth}.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement