ARTHEVAL - Arithmetic Evaluation

no tags 

Evaluate a parenthesized expression of single-digit positive integers and the binary operators +, -, *.

The order of operations differs from the canonical one in that operations have no precedence; they are simply evaluated from left-to-right, with only parentheses affecting the order of evaluation.

Every intermediate step is guaranteed to have absolute value no greater than 1,000,000,000.

Input:

Input is an arithmetic expression of single-digit positive integers, the binary operators +, -, * and parentheses ( ). The arithmetic expression will be well-formed and will have no spaces.

Output:

The evaluated value of the arithmetic expression.

Example Input 1: Example Input 2: Example Input 3:
1*2+1
1+1*2
(5*6)-(4+(1))
Example Output 1: Example Output 2: Example Output 3:
3
4
25

hide comments
Simes: 2023-08-02 20:41:08

I've corrected the 3rd example to remove the double-digit integer.

Saurabh Suman: 2017-05-03 13:21:16

Input might contain '0'

Kriti Joshi: 2014-12-18 06:09:41

Input only contains positive single digit integers. AC in one go :)

Last edit: 2014-12-18 06:10:06
Mitch Schwartz: 2012-04-10 19:02:23

Based on my experiment, all the integers in the input are single-digit, so you may ignore the third example.

Daniel Hui: 2012-04-07 17:27:28

Are you sure all integers are single-digit? Your third example input has a two-digit integer.

Last edit: 2012-04-07 17:27:36

Added by:Paul Draper
Date:2012-04-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64