80pts???
查看原帖
80pts???
539770
ggggcyyyy楼主2022/10/16 23:20

代码应该很易懂

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b=1,t,c,d,mx,mn,n,opt;
int i,j;
signed main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>c>>d>>opt;
		if(c==0||d==0) continue;
		t=b;
		mx=b*t;
		a*=d,b*=d;
		c*=t,d*=t;
		if(opt==1)
			a+=c;
		else
			a-=c;
		mn=__gcd(a,b);
		a/=mn,b/=mn;
	}
	mn=__gcd(a,b);
	a/=mn,b/=mn;
	if(a%b==0||a==0) cout<<a/b;
	else cout<<a<<"/"<<b;

	return 0;
}

2022/10/16 23:20
加载中...