mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
28 lines
3.5 KiB
HTML
28 lines
3.5 KiB
HTML
Rational Sum
|
|
<div class="ques-view"><p>Given <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> rational numbers in the form <code>numerator/denominator</code>, you are supposed to calculate their sum.</p>
|
|
<h3 id="input-specification-">Input Specification:</h3>
|
|
<p>Each input file contains one test case. Each case starts with a positive integer <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo><mn>1</mn><mn>0</mn><mn>0</mn></mrow>\le 100</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.78041em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span><span class="mord mathrm">1</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span></span></span></span>), followed in the next line <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> rational numbers <code>a1/b1 a2/b2 ...</code> where all the numerators and denominators are in the range of <strong>long int</strong>. If there is a negative number, then the sign must appear in front of the numerator.</p>
|
|
<h3 id="output-specification-">Output Specification:</h3>
|
|
<p>For each test case, output the sum in the simplest form <code>integer numerator/denominator</code> where <code>integer</code> is the integer part of the sum, <code>numerator</code> <span class="katex"><span class="katex-mathml"><math><mrow><mo><</mo></mrow><</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.5391em;"></span><span class="strut bottom" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="base textstyle uncramped"><span class="mrel"><</span></span></span></span> <code>denominator</code>, and the numerator and the denominator have no common factor. You must output only the fractional part if the integer part is 0.</p>
|
|
<h3 id="sample-input-1-">Sample Input 1:</h3>
|
|
<pre><code class="lang-in">5
|
|
2/5 4/15 1/30 -2/60 8/3
|
|
</code></pre>
|
|
<h3 id="sample-output-1-">Sample Output 1:</h3>
|
|
<pre><code class="lang-out">3 1/3
|
|
</code></pre>
|
|
<h3 id="sample-input-2-">Sample Input 2:</h3>
|
|
<pre><code class="lang-in">2
|
|
4/3 2/3
|
|
</code></pre>
|
|
<h3 id="sample-output-2-">Sample Output 2:</h3>
|
|
<pre><code class="lang-out">2
|
|
</code></pre>
|
|
<h3 id="sample-input-3-">Sample Input 3:</h3>
|
|
<pre><code class="lang-in">3
|
|
1/3 -1/6 1/8
|
|
</code></pre>
|
|
<h3 id="sample-output-3-">Sample Output 3:</h3>
|
|
<pre><code class="lang-out">7/24
|
|
</code></pre>
|
|
</div> |