20分求助
  • 板块P8584 探索未知
  • 楼主卷王慢即快
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/10/16 19:40
  • 上次更新2023/10/27 07:13:05
查看原帖
20分求助
494699
卷王慢即快楼主2022/10/16 19:40
#include<bits/stdc++.h>
using namespace std;
int n;
long long fm=1,fz=0;
inline int gcd(int x,int y) { return y==0?x:gcd(y,x%y); }
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long a,b,opt;
		cin>>a>>b>>opt;
		if(opt==1) fz=fz*b+fm*a; //计算 
		else fz=fz*b-fm*a;
		fm*=b;
		int ______gcd______=gcd(fm,fz); //约分 
		fm/=______gcd______;
		fz/=______gcd______;
	}
	if(fm==fz) cout<<"1";
	else if(fz==0) cout<<"0";
	else if(fm<0) cout<<-fz<<"/"<<-fm;
	else cout<<fz<<"/"<<fm;
	return 0;
}

WA记录

2022/10/16 19:40
加载中...