ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Linear Data structures: Stacks, Queues, Linked Lists, etc > задача:


50775 - Balanced Parenthesis

Гость
• Обсуждение задачи (1)

Задачи раздела

• 50262 - Brackets
• 50291 - Postfix Arithmetic Expressions
• 50286 - Remove Duplicates
• 50775 - Balanced Parenthesis
• 50340 - Game 19
• 50877 - Friendly Queue
• 51086 - Top popular student
• 50774 - Hot Potato
• 50777 - Dwarfs Maze
• 50781 - ReversesreveR
• 50780 - Hot Potato - Revisited
• 50564 - Kovat e qumeshtit te mamase

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 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

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

www.contester.ru