# L1-009N个数求和

### 题目描述：

5
2/5 4/15 1/30 -2/60 8/3

3 1/3

2
4/3 2/3

2

3
1/3 -1/6 1/8

7/24

#include<iostream>
using namespace std;

//GreatestCommonDivisor
long long GCD(long long a, long long b)
{
long long temp;
if (a < b)
{
temp = a;
a = b;
b = temp;
}

while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return a;
}

//LeastCommonMultiple
long long LCM(long long a, long long b,long long c)
{
long long t = a * b /c;
return t;
}

int main()
{
long long N;
cin>>N;

long long top[N];
long long bottom[N];
for(int i=0;i<N;i++)
{
long long num1,num2;
char chr;
cin>>num1;
cin>>chr;
cin>>num2;
top[i] = num1;
bottom[i] = num2;
}

long long denominator = bottom[0];
for(int i=1;i<N;i++)
{
denominator = LCM(denominator,bottom[i],GCD(denominator,bottom[i]));
}

long long numerator = 0;
for(int i=0;i<N;i++)
{
numerator += (denominator/bottom[i])*top[i];
}

//get Integer
if(numerator>denominator)
{
long long integer = numerator/denominator;
cout<<integer;
numerator -=  denominator*integer;
if(numerator==0)
{
return 0;
}
cout<<" ";
}

long long num = GCD(denominator,numerator);
cout<<numerator/num;
if(denominator/num!=1)
cout<<"/"<<denominator/num<<endl;
return 0;
}