Equation Solver

View as PDF

Submit solution

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

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 1\,000 terms with all numbers greater than 0 and less than or equal to 1\,000.

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



  • -3
    Arihan10  commented on July 6, 2019, 11:18 p.m. edit 3

    Ah... Time to pull out the good old snake again...

  • -5
    Kirito  commented on July 28, 2016, 8:28 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.