20pts求助!!!
  • 板块P1572 计算分数
  • 楼主hby110
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/19 19:16
  • 上次更新2025/1/19 21:44:12
查看原帖
20pts求助!!!
1496920
hby110楼主2025/1/19 19:16

请各位大佬Debug,解必谢!!!

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x1=0,y1=0,x2=0,y2=1,x;
    while(~scanf("%d/%d",&x1,&x2)){
        y1=x1*y2+x2*y1,y2=x2*y2;
        x=__gcd(y1,y2);
        y1/=x;
        y2/=x;
    }
    if(y1<0&&y2<0){
        y1=-y1;
        y2=-y2;
    }else if(y1<0&&y2>0){
        y1=-y1;
        putchar('-');
    }else if(y1>0&&y2<0){
        y2=-y2;
        putchar('-');
    }
    if(!y1){
        puts("0");
    }else if(y2==1){
        cout<<y1<<endl;
    }else{
        cout<<y1<<"/"<<y2;
    }
    return 0;
}
2025/1/19 19:16
加载中...