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

Сборники > Data Structures > задача:


50291 - Postfix Arithmetic Expressions

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

Задачи сборника

• 50790 - Fire Alarm
• 50710 - Permutations
• 50709 - k-ary Strings
• 50708 - Binary Strings
• 50694 - The Cheapest Flight
• 50996 - Checkers - the shortest path
• 50770 - Average Depth
• 50796 - KNN
• 50291 - Postfix Arithmetic Expr...
• 50340 - Game 19
• 50836 - Censored
• 51000 - Book Index
• 50505 - kht Puzzle
• 51076 - Key person
• 51062 - Fish Pond II
• 51067 - Jumping frog
• 50840 - Tanker trucks

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

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

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Prepared by Ibrahim Mesecan.

Postfix Arithmetic Expressions

In computer science arithmetic expressions can be written in three different styles.

  1. Infix e.g. (3*6) + (4*7) = 46
  2. Prefix e.g. + * 3 6 * 4 7 = 46
  3. Postfix e.g. 3 6 * 4 7 * + = 46

Question: Write a program that is going to read a post fix expression and then evaluate and show the result on screen.
Note: Use Stacks to solve the problem.

Input specification
A postfix arithmetic expression will be given ending with an equal operator (=).
The expression may contain only numbers and 5 arithmetic operators: '+', '-', '*', '/', and '='.
The numbers will be preceded by '#'. Operators and operands are separated by spaces.
There are at most 10 consecutive numbers in the given expression.

Output specification
Calculate and show one integer: the result of postfix expression.

Sample Input I
  #6 #7 #12 #6 / + * #21 - =
Sample Input II
  #3 #5 #6 * + #13 - #18 #2 / + =
Sample Output I
  33
Sample Output II
  29

Output Explanation :
The expression given in the first sample can be written as:    6 * (7 + (12 / 6)) - 21 = 33


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

www.contester.ru