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

Разделы > Linear Data Structures: Arrays > задача:


51119 - Evaluating Prefix expressions

Гость
• Вопросы к жюри (1)

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

• 51117 - The Most Crowded
• 51146 - Popular Baby Names
• 51131 - Running After a Thief
• 51143 - Departments Competition
• 50994 - The Most Crowded Station
• 51118 - Place 7 to the 5th position
• 51132 - Problem Solving Competition
• 51121 - Complexity power of a nu...
• 51119 - Evaluating Prefix expr...
• 50563 - Modul i gjate
• 50594 - Transformimet
• 51182 - Count and Sum 2
• 51193 - The max element of k-th co...
• 51194 - The difference between max...
• 51196 - The sum of two arrays
• 51197 - Even and odd Numbers
• s

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

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

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

Evaluating Prefix expressions

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

  • Infix e.g. (3*6) + (4*7) = 46
  • Prefix e.g. + * 3 6 * 4 7 = 46 (first operator, then the numbers come)
  • Postfix e.g. 3 6 * 4 7 * + = 46 (first operands, then the operators come)
Question:Write a program that is going to read a prefix expression and then evaluate and show the result on screen.

Input specification: A prefix 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 40 consecutive numbers in the given expression.

Output specification: Calculate and show the result on screen.

Sample Input I Sample Input II
+ * #3 #6 * #4 #7 =
- * / #15 - #8 + #1 #1 #3 + #2 + #1 #1 =
Sample Output I Sample Output II
46 3.5

Explanation: The expression given in the second sample can be written as: ((15 / (8 - (1 + 1))) * 3) - (2 + (1 + 1)) = 3.5



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

www.contester.ru