Last active
May 9, 2024 08:27
-
-
Save FleamRus/916a2121b1b921169806840f544281fa to your computer and use it in GitHub Desktop.
Скобочное выражение
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Скобочное_выражение | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
char[] symbols = new char[10]; | |
char open = '('; | |
char close = ')'; | |
int depth = 0; | |
int maxDepth = 0; | |
Console.WriteLine("Сторока со скобочками: \n"); | |
for (int i = 0; i < symbols.Length; i++) | |
{ | |
symbols[i] = Convert.ToChar(random.Next(open , close +1)); | |
Console.Write(symbols[i]); | |
} | |
for (int i = 0;i < symbols.Length; i++) | |
{ | |
if (symbols[i] == open) | |
{ | |
depth++; | |
if (depth > maxDepth) | |
{ | |
maxDepth = depth; | |
} | |
} | |
else if (symbols[i] == close) | |
{ | |
depth--; | |
} | |
if (depth < 0) | |
{ | |
break; | |
} | |
} | |
if (depth == 0) | |
{ | |
Console.WriteLine("\nМаксимальная глубина вложения : " + maxDepth); | |
} | |
else | |
{ | |
Console.WriteLine("\nВыражение некорректное"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment