the requirement of the subject is very simple, that is, to find the number of N. The trouble is that these numbers are given in the form of a rational number "numerator/denominator", and that the and you output must also be in the form of rational numbers.
Input format:
Enter the first line to give a positive integer n (<=100). The following line gives the n rational number in the format "A1/b1 a2/b2 ...". The title guarantees that all molecules and denominators are within the long range. In addition, the sign of a negative number must appear in front of the molecule.
Output format:
Output the simplest form of the number and the result is written as "integral fractional fraction", where fractional portions are written as "numerator/denominator", requiring molecules to be less than the denominator, and they have no common factor. If the integer portion of the result is 0, only the fractional portion is printed.
Input Sample 1:
52/5 4/15 1/30-2/60 8/3
Output Example 1:
3 1/3
Input Sample 2:
24/3 2/3
Output Example 2:
2
Input Sample 3:
31/3 -1/6 1/8
Output Example 3:
7/24
Very simple a question, debugging for a long time. Alas, it is important that these sets of test cases:
3
0/1 0/2 0/3
1
2/10
3
0/1 0/2 5/10
Plus the three sets of test cases he gave.
There is a loophole in the problem. The 26th line of the following code, if the number is large, may be out of bounds. But he still passed it. Another point is that the input time-division mother is 0, this situation, the following code is not considered, but also passed.
1#include <stdio.h>2 3 Long LonggcdLong LongALong Longb) {4 if(A = =0)5 return 0;6 Else7 return(b = =0) ? A:GCD (b, a%b);8 }9 Ten intMain () { One intN; A Long LongLCP; - Long Longa,b,c,d; - inti =1; thescanf"%d",&N); -scanf"%lld/%lld",&a,&b); - intT0 =gcd (A, b); - if(a) { +A/=t0; -b/=t0; + } A at while(I <N) { -scanf"%lld/%lld",&c,&d); -LCP = B/GCD (b,d) *D; -A = A * lcp/b + c * LCP/D; -b =LCP; - intT0 =gcd (A, b); in if(T0! =0){ -A = A/t0; toB = b/t0; + } -i++; the } * if(A && A/b = =0)///the whole number is divided into 0 and a is not 0 . $printf"%lld/%lld\n", a%b,b);Panax Notoginseng Else if(A%b = =0)///The number of decimal parts is divided into 0 -printf"%lld\n", A/b); the Else +printf"%lld%lld/%lld\n", a/b,a%b,b); A return 0; the}
l1-009. Sum of n number