HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50775 - Balanced Parenthesis

Guest
• Discussion of problem (1)

Volume problems

• 50790 - Fire Alarm
• 50710 - Permutations
• 50709 - k-ary Strings
• 50708 - Binary Strings
• 50694 - The Cheapest Flight
• 50996 - Checkers - the shortest path
• 50770 - Average Depth
• 50291 - Postfix Arithmetic Expressions
• 50775 - Balanced Parenthesis
• 50736 - Top N Donors - 2
• 50796 - KNN
• 50340 - Game 19
• 50735 - Top M Products
• 50697 - Base Stations
• 50383 - Noisy Mornings
• 50479 - Bit Compressor
• 50674 - Collecting Eggs

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Prepared by Ibrahim Mesecan. Difficulty Beta

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

Для отправки решений необходимо выполнить вход.

www.contester.ru