Start: Jun, 26, 2019 08:30:00
2019年度暑期短学期第一天
End: Jun, 26, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 6ms
Memory: 1716kB
Author: 2018212212030
In contest: 1273

#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <list>
using namespace std;
#define ll long long                                               
#define inf 0x3f3f3f3f
int i, j, k;
int m, n, p;
ll gcd(ll a, ll b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
ll ccl(ll a, ll b, ll& c, ll& d) {
	a *= d, c *= b, b *= d, d = b;
	c += a;
	ll g = gcd(c, d);
	c /= g;
	d /= g;
	ll sum = c / d;
	c %= d;
	return sum;
}

int main() {
	ll a = 0, b = 0, c = 0, d = 0, sum = 0;
	ll t = 0;
	scanf("%lld", &t);
	while (t--) {
		scanf("%lld/%lld", &a, &b);
		if (c == 0) {
			c = a;
			d = b;
		}
		else
			sum += ccl(a, b, c, d);
	}
	if (sum != 0) {
		printf("%lld", sum);
		if (c > 0)
			printf(" %lld/%lld", c, d);
		else if (c < 0)
			printf(" %lld/%lld", -c, d);
	}
	else {
		if (c == 0)
			printf("0");
		else
			printf("%lld/%lld", c, d);
	}
	printf("\n");
	return 0;
}