提交时间:2023-11-07 20:57:32

运行 ID: 30389

#include<bits/stdc++.h> using namespace std; iny a[20],b[20]; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } int main(){ int n,cnt=0,n1=0,n2=0,d; char s[20]; cin>>n; while(n){ cin>>a[cnt]>>s[cnt]>>b[cnt]; cnt++; } for(int i=0;i<cnt;i++) n2*=b[i]; for(int i=0;i<cnt;i++) n1+=n2*a[i]/b[i]; d=gcd(n1,n2); n1/=b; n2/=b; if(n2==1) cout<<n1; else cout<<n1<<"/"<<n2; return 0; }