#GL0000387. Phép tính số hữu tỉ (Rational Arithmetic)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phép tính số hữu tỉ (Rational Arithmetic)
Rational Arithmetic
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given two rational numbers and and an operation +, -, *, or /, compute the exact result. Output the reduced fraction , where and .
Division appears only when the second fraction is nonzero. For a zero result, print 0 / 1.
PHOJ convention: Each .in file contains exactly one arithmetic expression, with no leading count. The original Kattis format may contain multiple expressions; those are split into separate PHOJ test files. The bounds below are those of this PHOJ Extended version.
Input
One line with five fields , where op belongs to +, -, *, /.
Output
A single line p / q, using one space around the slash, where is positive and the fraction is reduced.
Subtasks
-
Subtask 1 (20 points): and .
-
Subtask 2 (30 points): and .
-
Subtask 3 (50 points): and .
In every subtask, op / guarantees .
Examples
Example 1
Input
1 2 + 1 3
Output
5 / 6
Explanation
.
Example 2
Input
-6 8 / 3 -4
Output
1 / 1
Explanation
Both input fractions equal , so their quotient is , printed as 1 / 1.
Example 3
Input
7 9 - 7 9
Output
0 / 1
Explanation
The difference is zero. Its normalized representation has denominator .