| Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|
| 30391 | Andrew宥杨 | 分数求和 | C++ | Time Limit Exceeded | 1000 MS | 240 KB | 431 | 2023-11-07 20:58:02 |
#include<bits/stdc++.h> using namespace std; int 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/=d; n2/=d; if(n2==1) cout<<n1; else cout<<n1<<"/"<<n2; return 0; }