0
已采纳
李奕歌
初级天翼
初级天翼
核心:
while(ch=getchar()){
if(ch!='+'&&ch!='-') break;
scanf("%d/%d", &tmp_fz, &tmp_fm);
//求
icm = tmp_fm/gcd(tmp_fm, fm)*fm;
fz *= icm/fm;
tmp_fz *= icm/tmp_fm;
fm = icm;
if(ch=='+')
fz += tmp_fz;
else if(ch=='-')
fz -= tmp_fz;
//约分
int yf = gcd(abs(fz), fm);
fz /= yf;
fm /= yf;
}
1
0
0