Rational numbers (4) P26141


Statement
 

pdf   zip

Using the procedures done in the exercises RACI1, RACI2 and RACI3, your task is to write a program that reads a sequence of rational numbers and operations r0o1r1o2r2on1rn1onrn,r_0 \quad o_1 \enspace r_1 \quad o_2 \enspace r_2 \quad \dots \quad o_{n - 1} \enspace r_{n - 1} \quad o_{n} \enspace r_{n} \quad , and prints the result after each operation.

Input

Input consists of a line with an initial rational, followed by a sequence of lines, each one with a pair operation/rational. As in the exercise RACI2, each rational is given by a pair of integer numbers, the second integer is not zero. The operations can be “add”, “substract”, “multiply” or “divide”. In this last case, the second rational is not zero.

Output

Your program must print the initial rational, followed by the accumulated result of each operation. Each rational number must be in a different line.

Public test cases
  • Input

    1 2
    add 5 2
    substract 2 1
    multiply 10 1
    divide 3 1
    

    Output

    1/2
    3
    1
    10
    10/3
    
  • Input

    3 -6
    substract 0 5
    add -2 -4
    divide 1 1
    

    Output

    -1/2
    -1/2
    0
    0
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python