#C6281. Arithmetic Expression Evaluator

    ID: 50024 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluator

Arithmetic Expression Evaluator

You are given a string that represents a simple arithmetic expression. The expression contains non-negative integers along with the + and - operators, and may include spaces. Your task is to evaluate the expression and output the result as an integer.

The expression follows the grammar:

\( \text{expression} = \text{number} \ ((+|-) \text{number})^* \)

where each number is a non-negative integer (possibly with multiple digits).

For example:

  • "3+2-5" evaluates to \(0\).
  • "10 + 2 - 6" evaluates to \(6\).
  • "100 - 20 + 5 - 5" evaluates to \(80\).

Your solution must read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input consists of a single line containing the arithmetic expression. The expression may contain spaces, digits, and the operators + and -.

Example:

 100 - 20 + 5 - 5 

outputFormat

Output a single integer which is the result of evaluating the expression.

Example:

80
## sample
3+2-5
0