UVa 327

From Algorithmist
Jump to navigation Jump to search
This is a stub or unfinished. Contribute by editing me.

327 - Evaluating Simple C Expressions[edit]

Summary[edit]

Evaluate a C expression consisting only of addition, subtraction, ++, and --.

Optimizations[edit]

  • Keep two copies of the expression. One (which must be pristine) for the output and one that you can play with.
  • Try prepending a + to the expression.
  • Keep the lax constraints in mind: each variable appears only once, no ambiguity, etc.

Input[edit]

a + b
b - z
a+b--+c++
c+f--+--a
   f-- + c-- + d-++e

Output[edit]

Expression: a + b
    value = 3
    a = 1
    b = 2
Expression: b - z
    value = -24
    b = 2
    z = 26
Expression: a+b--+c++
    value = 6
    a = 1
    b = 1
    c = 4
Expression: c+f--+--a
    value = 9
    a = 0
    c = 3
    f = 5
Expression:    f-- + c-- + d-++e
    value = 7
    c = 2
    d = 4
    e = 6
    f = 5