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: 7ms
Memory: 1712kB
Author: 2017212212174
In contest: 1273

#include<bits/stdc++.h>

using namespace std;

int p[3][102],da,db; 

void yf(){
	int date=0;
	if(da<0){
		date=1;
		da*=-1;
	}
	int minn=min(da,db);
	for(int i=minn;i>0;i--){
		if(da%i==0&&db%i==0){
			da/=i;db/=i;
			if(date)da*=-1;
			break;
		}
	}
}
int main(){
	int n,a,b;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d/%d",&a,&b);
		p[1][i]=a;p[2][i]=b;
	}
	da=p[1][1];db=p[2][1];
	for(int i=2;i<=n;i++){
		a=p[1][i];b=p[2][i];
		da=da*b+db*a;db*=b;
		yf();
	}
	if(da==0)cout<<0;

	else{
		if(da<0){
			cout<<'-';
			da*=-1;
		}
		int z;
		z=da/db;
		da%=db;
		if(z)cout<<z;
		if(da){
			if(z)cout<<' ';
			cout<<da<<'/'<<db;
		}	
	}

	return 0; 
}