mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-30 00:37:37 +08:00
32 lines
1.6 KiB
HTML
32 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1088. Rational Arithmetic (20)</h1>
|
|
<div id="problemContent">
|
|
<p>For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case, which gives in one line the two rational numbers in the format "a1/b1 a2/b2". The numerators and the denominators are all in the range of <i>long int</i>. If there is a negative sign, it must appear only in front of the numerator. The denominators are guaranteed to be non-zero numbers.</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each test case, print in 4 lines the sum, difference, product and quotient of the two rational numbers, respectively. The format of each line is "number1 operator number2 = result". Notice that all the rational numbers must be in their simplest form "k a/b", where <b>k</b> is the integer part, and <b>a/b</b> is the simplest fraction part. If the number is negative, it must be included in a pair of parentheses. If the denominator in the division is zero, output "Inf" as the result. It is guaranteed that all the output integers are in the range of <i>long int</i>.</p>
|
|
<b>Sample Input 1:</b><pre>
|
|
2/3 -4/2
|
|
</pre>
|
|
<b>Sample Output 1:</b><pre>
|
|
2/3 + (-2) = (-1 1/3)
|
|
2/3 - (-2) = 2 2/3
|
|
2/3 * (-2) = (-1 1/3)
|
|
2/3 / (-2) = (-1/3)
|
|
</pre>
|
|
<b>Sample Input 2:</b><pre>
|
|
5/3 0/6
|
|
</pre>
|
|
<b>Sample Output 2:</b><pre>
|
|
1 2/3 + 0 = 1 2/3
|
|
1 2/3 - 0 = 1 2/3
|
|
1 2/3 * 0 = 0
|
|
1 2/3 / 0 = Inf
|
|
</pre>
|
|
</div> |