Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ijunior
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите скобочное выражение: ");
- string userInput = Console.ReadLine();
- char[] frames = userInput.ToCharArray();
- int tempDeepFrames = 0;
- int deepFrames = 0;
- char openFrame = '(';
- char closeFrame = ')';
- foreach (char frame in frames)
- {
- if (frame == openFrame)
- {
- tempDeepFrames++;
- if (deepFrames < tempDeepFrames)
- {
- deepFrames = tempDeepFrames;
- }
- }
- else if (frame == closeFrame)
- {
- tempDeepFrames--;
- }
- if (tempDeepFrames < 0)
- {
- break;
- }
- }
- if (tempDeepFrames == 0)
- {
- Console.WriteLine("Уровень вложенности: " + deepFrames);
- }
- else
- {
- Console.WriteLine("Неверное выражение");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment