#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){ return !b? a:gcd(b,a%b);}//最大公约数
int main(){
int n;
scanf("%d",&n);
long long t_fz,t_fm,t_zs=0;
long long res_fz=0,res_fm=1,res_zs=0;
for(int i=0;i<n;i++){
scanf("%lld/%lld",&t_fz,&t_fm);
long long t_gcd=gcd(t_fz,t_fm);
t_fz/=t_gcd,t_fm/=t_gcd;//化简
t_zs=t_fz/t_fm,t_fz=t_fz%t_fm;//带分数
if(t_fm==res_fm){
res_fz+=t_fz;
}else{//res_fz*t_fm+t_fz*res_fm/t_fm*res_fm
t_fm*=res_fm;//t_fm*res_fm
t_fz*=res_fm;//t_fz*res_fm
res_fz*=(t_fm/res_fm);
res_fz+=t_fz;
res_fm=t_fm;
}
long long res_gcd=gcd(res_fz,res_fm);
res_fz/=res_gcd,res_fm/=res_gcd;//化简
res_zs+=(t_zs+res_fz/res_fm),res_fz=res_fz%res_fm;//带分数
}
if(res_zs!=0){//有整数部分
printf("%lld",res_zs);
if(res_fz!=0){//有小数部分
if(res_fm!=1) printf(" %lld/%lld",res_fz,res_fm);//小数部分为整数
else printf(" %lld",res_fz);
}
}else{//没有整数部分
if(res_fm!=1) printf("%lld/%lld",res_fz,res_fm);
else printf("%lld",res_fz);
}
return 0;
}
03-03
496
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-21
1348
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)