Preparando MOJI
In this problem we'll use a stack which supports two types of operations:
You are given a string which describes the sequence of operations to be performed on the stack. i-th character corresponds to i-th operation:
Initially the stack is empty. Output the topmost number on the stack after executing all given operations.
The only line of input contains a string of operations, consisting of characters «+», «*» and digits (0..9). The length of the string will be between 1 and 20 characters, inclusive.
The given sequence of operations is guaranteed to be correct, i.e. the stack will have at least two elements before every math operation. The numbers on the stack will never exceed 106.
Output a single number — the topmost element of the stack after performing all given operations.
12+3*66*+
45
149
9
In the first case the stack will end up containing a single number — the result of calculating (1+2)*3+6*6.
In the second case there are no math operations, so the answer will be the last number pushed on the stack.