ÀÂÒ
Language: Russian
English

Remote Training on Programming

Problems Online status Contests
News FAQ E-learning
For authors:
Register  ||  Login
 
Hello, Guest! Please login or register.

1630. Fractional Arithmetics

Time Limit: 1 seconds
Memory Limit:262144KB
Points:100
View Problem Statistics Submit Problem added debug

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”. Limitations
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.

Input

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.

Output

A single line that contains an irreducible proper fraction (result) in the format described above.

Sample

InputOutput
-3 1/6
+
2/4
-2 2/3

View Problem Statistics Submit Problem discussion Author/source:
Sorted Problems / Mathematics / Theory of numbers /
17. Factorials 2 1630. 34. GCD & LCS 179. Great Triangle Area 1484. Last Digit
Problems from Contests and Camps / School olympiads and couses of Vologda region / Impulse - 2019 / Number Theory /
1650. 04 - Divisors-2 1630. 482. 06 - Multiple with equal digits 1351. 07 - Prime Numbers 1736. 08 - Sum of Digits
Problems from Contests and Camps / School olympiads and couses of Vologda region / Impulse, september 2020 / Impulse-2020, number theory /
1650. 04 - Divisors-2 1630. 482. 06 - Multiple with equal digits 1736. 07 - Sum of Digits 1739. 08 - Euler Function
time generating 0.422 sec.
© Copyright VSU, AVT, Nosov D.A., Andrianov I.A.