#include<fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct rational {int nr, nu;};
int cmmdc(int a, int b)
{
if (a % b == 0) return b;
else return cmmdc(b, a % b);
}
void simplific(rational &r)
{
int c = cmmdc(abs(r.nr), abs(r.nu));
r.nu = r.nu / c;
r.nr = r.nr / c;
if(r.nr*r.nu<0)
{
r.nu=abs(r.nu);
r.nr=-abs(r.nr);
}
else
{
r.nu=abs(r.nu);
r.nr=abs(r.nr);
}
}
void citire(rational &r)
{
fin>>r.nr>>r.nu;
simplific(r);
}
void afisare(rational r)
{
fout<<r.nr<<"/"<<r.nu<<" ";
}
rational adunare(rational x, rational y)
{
int a = x.nr * y.nu + x.nu * y.nr;
int b = x.nu * y.nu;
rational r;
r.nr=a; r.nu=b;
simplific(r);
return r;
}
int main()
{
int n,i;
rational a,s;
fin>>n;
citire(a);
s=a;
for(i=2;i<=n;i++)
{
citire(a);
s=adunare(s,a);;
}
afisare(s);
fin.close();
fout.close();
return 0;
}
|