#K72942. Compute Final Value from Operations

    ID: 33865 Type: Default 1000ms 256MiB

Compute Final Value from Operations

Compute Final Value from Operations

You are given a string consisting of space-separated tokens representing operations to be performed on an initial variable set to 0. Each token can either be an increment operator (++), a decrement operator (--), or an integer value. The operators ++ and -- are equivalent to adding or subtracting one respectively.

The task is to compute the final value after processing all tokens sequentially.

More formally, let \( v \) be the initial value (i.e., \( v=0 \)). For each token t in the input:

  • If \( t = \texttt{++} \), then \( v = v + 1 \).
  • If \( t = \texttt{--} \), then \( v = v - 1 \).
  • Otherwise, convert \( t \) to an integer and add it to \( v \).

Output the final value of \( v \) after all operations.

inputFormat

The input consists of a single line containing a series of tokens separated by spaces. Each token is either ++, --, or an integer (which may be negative).

outputFormat

Output a single integer: the final value after processing all operations.

## sample
++ 5 -- -3 ++ 2
5