Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Prepared by Ibrahim Mesecan.
Сложность Бета
Balanced Parenthesis
An application of a stacks is to determine whether the parentheses in an expression are balanced. For example, the expression
(a + [c / d] )
1 2 2 1
has balanced parentheses. We can solve this problem without using a stack by ignoring all
characters except the symbols (, ), [, ], {, and }.
For example, the expression
(a + b * {c / [d - e]}) + (d / e)
is balanced, but the expression
(a + b * {c / [d - e } ) + (d / e)
is not because the subexpression [d - e} is incorrect.
Question: Write a program that is going to read the an arithmetic expression, and decide if it's
balanced or not.
Note: Use Stacks to solve the problem.
Input specification
You will be given an expression which might include numbers arithmetic operators and the set of
parenthesis symbols: (, ), [, ], {, and }.
The expression will be in one line and containing at most 100 chars including the spaces.
Output specification
If the expression is balanced show "Balanced", otherwise show "Not Balanced" on screen.
Sample Input I
(a + b * {c - e } ) + ( d / e
|
Sample Input II
(a * {c - e } )
|
Sample Output I
Not Balanced
|
Sample Output II
Balanced
|
Для отправки решений необходимо выполнить вход.
|