关于下载的样例在自己电脑都过在这全WA
查看原帖
关于下载的样例在自己电脑都过在这全WA
627293
FanMingxuan楼主2022/10/23 00:56

为啥下载的样例在自己电脑都过在这全WA

代码:

#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
long long gcd(long long x,long long y) {
	x = x ? x : 1;
	int temp = min(x,y);
	y = max(x,y);
	x = temp;
	long long r = y % x;
	while(r) {
		y = x;
		x = r;
		r = y % x;
	}
	//cout<<x<"GGG";
	return x;
}
int main() {
	long long a,b,op,n;
	long long aa = 0,ab = 1;
	cin>>n;
	for(int i = 0; i < n; ++ i) {
		scanf("%d %d %d",&a,&b,&op);
		long long a1,b1;
		a1 = ((op - 1) ? aa * b - a * ab : aa * b + a * ab);
		//cout<<a1;
		b1 = b * ab;
		long long r = abs(gcd(a1,b1));
		//cout<<r<<endl;
		aa = a1 / r;
		ab = b1 / r;
	}
	long long K = abs(gcd(aa,ab));
	aa = aa / K;
	ab = ab / K;
	cout<<aa;
	if(ab != 1) cout<<"/"<<ab;
	return 0;
}
2022/10/23 00:56
加载中...