R
R
Roman Shavukhin2020-11-09 16:18:27
IT education
Roman Shavukhin, 2020-11-09 16:18:27

How to solve such kind of problems?

Given a string that can contain 3 types of brackets: curly, square and round. In addition to parentheses, there are other sequences of characters in the string. The nesting of brackets can be arbitrary. It is necessary to check the correctness of the bracket notation: each opening bracket must correspond to the following closing bracket of the same type at the same nesting level, there should not be an opening or closing bracket without a pair.

I understand what exactly needs to be done, but I do not know how to implement

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-11-09
@dmshar

Checking the correct nesting of parentheses is a classic task that is used when explaining with the simplest example of work. stack. Thus - to your question "How to solve this kind of problem?" - I answer using the stack. The opening bracket corresponds to the operation of pushing a new element onto the stack. The closing brace is popping from the stack. If at the end of the data pass the stack is empty, the expression is correct. Otherwise, no.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question