Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char symbol1 = '(';
- char symbol2 = ')';
- string symbolLine = "( и )";
- int maximumDepth = 0;
- int symbolsCount = 0;
- for (int i = 0; i < symbolLine.Length; i++)
- {
- if (symbolLine[i] == symbol1)
- {
- symbolsCount++;
- if (symbolsCount > maximumDepth)
- {
- maximumDepth = symbolsCount;
- }
- }
- else if (symbolLine[i] == symbol2)
- {
- symbolsCount--;
- }
- }
- if (symbolsCount != 0)
- {
- Console.WriteLine("Не корректная запись.");
- }
- else
- {
- Console.WriteLine($"Строка корректная. Максимальная глубина - {maximumDepth}.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement