CEN254 Midterm |
Старт: 09.мая.2017 в 14:05:00
Финиш: 09.мая.2017 в 15:02:00
Турнир завершён!
• Турнирная таблица
|
|
Лимит времени 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
Для отправки решений необходимо выполнить вход.
|