Files
PAT/source/html/b1034.html
T

25 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
有理数四则运算
<div class="ques-view"><p>本题要求编写程序,计算 2 个有理数的和、差、积、商。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中按照 <code>a1/b1 a2/b2</code> 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为 0。</p>
<h3 id="-">输出格式:</h3>
<p>分别在 4 行中按照 <code>有理数1 运算符 有理数2 = 结果</code> 的格式顺序输出 2 个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式 <code>k a/b</code>,其中 <code>k</code> 是整数部分,<code>a/b</code> 是最简分数部分;若为负数,则须加括号;若除法分母为 0,则输出 <code>Inf</code>。题目保证正确的输出中没有超过整型范围的整数。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">2/3 -4/2
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">2/3 + (-2) = (-1 1/3)
2/3 - (-2) = 2 2/3
2/3 * (-2) = (-1 1/3)
2/3 / (-2) = (-1/3)
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">5/3 0/6
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">1 2/3 + 0 = 1 2/3
1 2/3 - 0 = 1 2/3
1 2/3 * 0 = 0
1 2/3 / 0 = Inf
</code></pre>
</div>