Calculator Program
InterviewTime limit1sMemory limit128 MB
Read alternating numbers and operators, evaluate left to right ignoring precedence, and print the value when = appears.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Math, String
- Solved
- No attempts yet
Problem
Write a calculator program that can perform addition, subtraction, multiplication, and division.
Input
The input consists of several lines. Each line contains a number or one of the operators (+, -, *, /, =), given alternately. The first line is a number.
Operator precedence is ignored; the calculation is performed from left to right in the order the input is given. When = is given, print the result computed so far.
Each given number is a positive integer at most . An intermediate result may be or negative, but it never leaves the range .
In division, the fractional part is discarded. For example, 100 / 3 * 3 = 99.
Division in which the dividend (the number being divided) is negative is never given as input.
Output
Print the result of the calculation on the first line.