Your task is to write a program, which implements addition, subtraction, multiplication and division operations on fractions.
Input and output fraction format is as follows:
- the sign of a number (must be written only if its absence may lead to misrepresentation of the number),
- the integer part of a number (the integer part that equals zero must be omitted if the numerator and the denominator are present),
- a space character (must be omitted if the integer or fractional part is absent),
- the numerator (if it is not equal to zero),
- the “/” sign (written only if there is a numerator),
- the denominator (must be omitted if there is no numerator),
- the denominator cannot be equal to zero.
Samples of fractional number representation: “-7 3/4”, “8 1/2”, “-7/11”, “0”, “11”.
All limitations apply for both input and output data.
The sign of a fraction: if the fraction is positive, the sign is not written; if the fraction is negative, the “-” sign must be present.
The integer part and the numerator may have values ranging from 0 to 30000, the denominator may have values from 1 to 30000.
The operation sign may be one of the four possible symbols: “+” (addition), “-” (subtraction), “*” (multiplication), “/” (division).
The expression is always correct, so the second operand in the division operation cannot be zero.
The first line – a fraction (the first operand);
The second line – the sign of an operation;
The third line – a fraction (the second operand).
Both fractions may be reducible. The numerator is always less than the denominator.
A single line that contains an irreducible proper fraction (result) in the format described above.
Автор задачи: © Sergey G. Volchenkov, 2003(email@example.com); Vladimir N. Pinaev, 2003(firstname.lastname@example.org; http://www.pic200x.chat.ru); Michael Y. Kopachev, 2003 (email@example.com).
Источник задачи: 2003-2004 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 15-16, 2003