14283 - Fraction Calculator (Lite)   

Description

Your task is to create a basic fraction calculator that can handle the multiplication of fractions.

In the provided code, you are advised to use a structure called "FractionList", which functions similarly to a linked list. When performing a multiplication, add the new fraction to the end of the list. Then, multiply all the fractions in the list and output the answer.

This is a partial judge problem. You need to implement 3 class methods. Please review the provided code and refer to the sections labeled "TODO" in the function.h file for further details.

Important: Please select C++17 to submit your solution.

 

Input

The first line of the input contains an integer N, representing the number of test cases. (1 ≤ N ≤ 5 × 104)

Each of the following N lines represents a test case.
Each test case contains a sequence of fractions and operations formatted as follows:

<fraction_1> * <fraction_2> * ... * <fraction_n> =  (1 < n ≤ 15)

Each fraction is written in the format <numerator>/<denominator>, where both numerator and denominator, as well as all numbers involved in calculations, fit within the range of a long long data type. 

 

Output

For each test case, you should output the original problem and the result, with resulting fraction presented as a simplified fraction reduced to its lowest terms. The format for each test case should be as follows:

<fraction_1> * <fraction_2> * ... * <fraction_n> = <result_fraction>

Additional constraint:

  • If the result is an integer (e.g., 3), output should be formatted as: 3/1.
  • The result will not be 0.
  • It's guaranteed that all the fractions in the given problem are irreducible.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

14283.cpp

Partial Judge Header

14283.h

Tags




Discuss