RT,RE+WA,已知hack数据为: 3 1 1 1 2 1 2 1 1 1
调不出来,求助大佬
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
int nowa,nowb,n;
int main(){
nowa=0,nowb=1;
cin>>n;
while(n--){
int x,y,k;
cin>>x>>y>>k;
if(k==2)
x*=-1;
nowa=nowa*y+nowb*x;
nowb=nowb*y;
int g=gcd(abs(max(nowa,nowb)),abs(min(nowa,nowb)));
nowa/=g,nowb/=g;
}
if(nowb==1){
cout<<nowa;
return 0;
}
if(nowb==-1){
cout<<-nowa;
return 0;
}
if(nowa==0){
cout<<0;
return 0;
}
if(nowb<0){
cout<<"-";
nowb=-nowb;
}
cout<<nowa<<"/"<<nowb;
return 0;
}