Write a program that reads a fraction (as two integers) followed by a sequence of artimethic operations on fractions, and prints the final resulting fraction simplified.
The input consists of two integers (numerator and denominator of
initial fraction) followed by a sequence of zero or more triplets
(str, int, int). The string is
one of ’+’, ’-’, ’*’,
’/’, and the int’s correspond to the numerator and
denominator of the fraction to be operated. Denominators are always
strictly positive.
The program will accumulate each operation on the result of the previous. For instance:
3 4 # initial value is 3/4
+ 1 2 # add 1/2 to 3/4 (accumulated is 5/4)
* 3 2 # multiply 5/4 by 3/2 (accumulated is 15/8)
- 1 4 # substract 1/4 from 15/8 (accumulated is 13/8)
when the triplet sequence ends, the program prints the final
simplified fraction (13/8 in this example).
The input consists of two integers, followed by a sequence of zero or more triplets (operation, numerator, denominator). Denominators are always strictly positive.
The output is the final simplified fraction resulting from accumulating all operations in the input sequence. Denominator must be strictly positive.
Author: Lluís Padró
Generation: 2026-07-06T09:39:59.404Z
© Jutge.org, 2006–2026.
https://jutge.org