Equation Solver

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 32M

Authors:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Prep 3

You've made it to the weekend, and you're ready to sleep! While trying to fall asleep, a nagging voice repeatedly commands you to do your math homework first. Since you want to sleep as soon as possible, you decide to do the problems super quickly. But there's a problem — your math teacher thought it was a funny joke to give you tons of super easy problems. The teacher also thought it was funny to replace + signs with the character P and - signs with the character M. Instead of wasting your time solving each one by hand, you decide to write a program to solve them. The questions will only involve subtraction and addition, and have up to terms with all numbers greater than and less than or equal to .

Input Specification

Line 1: The equation, a sequence of numbers, P, and M. Each term will be space separated from each other character. The equation will be terminated by =. There will be at least one term in the sequence.

Output Specification

Output one integer, the solution (right side) of the equation.

Sample Input

5 P 13 P 27 M 35 =

Sample Output

10