20分求助急
样例全过
#include <iostream>
using namespace std;
int n,x=0,y=1,a,b,i,opt;
int gcd(int m,int n)
{
while(m!=0)
{
int mtemp=m;
m=n%m;
n=mtemp;
}
if(n>0) return n;
else return -n;
}
int main()
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>a>>b>>opt;
int xtemp=x; int ytemp=y;
y=b*ytemp;
if(opt==1)
x=xtemp*b+ytemp*a;
else x=xtemp*b-ytemp*a;
int gxy=gcd(x,y);
x/=gxy;
y/=gxy;
}
if(y==1) cout<<x;
else cout<<x<<"/"<<y<<endl;
return 0;
}