HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50775 - Balanced Parenthesis

Guest
• Discussion of problem (1)

Volume problems

• 50. 50718 - Elevator
• 50711 - Snail Trails
• 50674 - Collecting Eggs
• 50306 - Beautiful Numbers
• 50411 - Sum of the Leaves
• 50675 - Kruja Boys
• 50421 - Repairing road segments
• 50736 - Top N Donors - 2
• 50775 - Balanced Parenthesis
• 50774 - Hot Potato
• 50464 - From Tirana to Durres
• 50757 - National Elections - 1
• 50681 - Center of a Series
• 50753 - Average of the Nth Student
• 50735 - Top M Products
• 50795 - Trunk

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