当前位置:网站首页>1081 rational sum (20 points) points add up to total points
1081 rational sum (20 points) points add up to total points
2022-07-06 12:08:00 【Python ml】
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long gcd(long long a,long long b){
return b==0?abs(a):gcd(b,a%b);
}
int main() {
long long n,a,b,suma = 0, sumb = 1, gcdvalue;
cin>>n;
for(int i=0;i<n;i++){
// Add up the scores
scanf("%lld/%lld",&a,&b);
gcdvalue=gcd(a,b); // After entering, the numerator and denominator will be divided into
a=a/gcdvalue;
b=b/gcdvalue;
suma=a*sumb+suma*b; // And the previous cumulative sum suma/sumb Carry out general division and addition
sumb=b*sumb;
gcdvalue=gcd(suma,sumb); // Then sum it up and divide it all
suma=suma/gcdvalue;
sumb=sumb/gcdvalue;
}
long long integer=suma/sumb; // Output in the form of true fraction
suma=suma-integer*sumb;
if(integer!=0){
cout<<integer;
if(suma!=0){
cout<<" ";
}
}
if(suma!=0) cout<<suma<<"/"<<sumb;
if(suma==0&&integer==0)cout<<0;
system("pause");
return 0;
}
边栏推荐
- 机器学习--线性回归(sklearn)
- RT thread API reference manual
- Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
- 小天才电话手表 Z3工作原理
- GNN的第一个简单案例:Cora分类
- arduino获取数组的长度
- Keyword inline (inline function) usage analysis [C language]
- Raspberry pie tap switch button to use
- ES6 grammar summary -- Part 2 (advanced part es6~es11)
- I2C总线时序详解
猜你喜欢
随机推荐
XML file explanation: what is XML, XML configuration file, XML data file, XML file parsing tutorial
Cannot change version of project facet Dynamic Web Module to 2.3.
Rough analysis of map file
Some concepts often asked in database interview
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
荣耀Magic 3Pro 充电架构分析
RT-Thread API参考手册
C language, log print file name, function name, line number, date and time
机器学习--线性回归(sklearn)
OPPO VOOC快充电路和协议
小天才电话手表 Z3工作原理
[template] KMP string matching
Basic knowledge of lithium battery
MySQL数据库面试题
Important methods of array and string
Working principle of genius telephone watch Z3
Pytoch implements simple linear regression demo
Cannot change version of project facet Dynamic Web Module to 2.3.
Inline detailed explanation [C language]
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer