Calculator Program

Interview

Time limit1sMemory limit128 MB

Summary
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 10810^8. An intermediate result may be 00 or negative, but it never leaves the range −108∼108-10^8 \sim 10^8.

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.

Examples3

  1. Example 1

    Input
    1
    +
    1
    =
    
    Expected output
    2
    
  2. Example 2

    Input
    10
    -
    21
    *
    5
    =
    
    Expected output
    -55
    
  3. Example 3

    Input
    100
    /
    3
    *
    3
    =
    
    Expected output
    99