CEN254 Midterm |
Start: May.09.2017 at 02:05:00 PM
Finish: May.09.2017 at 03:02:00 PM
The contest is finished!
• Contest scoreboard
|
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. 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
Для отправки решений необходимо выполнить вход.
|