提交时间:2023-11-07 20:44:25

运行 ID: 30373

#include<iostream> using namespace std; int a[20],b[20]; int g(int a,int b); { if(b==0) return a; return g(b,a%b); } int main() { int n,c=0; int n1=0,n2=1,d; char s[20]; cin>>n; while(n--){ cin>>a[c]>>s[c]>>b[c]; c++; } for(int i=0;i<c;i++){ n2=n2*b[i]; } for(int i=0;i<c;i++){ n1=n1+n2*a[i]/b[i]; } n1/=b; n2/=b; if(n2==1) cout<<n1<<endl; else cout<<n1<<"/"<<n2<<endl; return 0; }