当前位置:网站首页>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;
}
边栏推荐
- Pytorch-温度预测
- There are three iPhone se 2022 models in the Eurasian Economic Commission database
- JS变量类型以及常用类型转换
- 互联网协议详解
- Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
- Kaggle competition two Sigma connect: rental listing inquiries
- Arduino JSON data information parsing
- C language, log print file name, function name, line number, date and time
- Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
- AMBA、AHB、APB、AXI的理解
猜你喜欢
[esp32 learning-2] esp32 address mapping
Basic use of pytest
JS 函数提升和var变量的声明提升
R & D thinking 01 ----- classic of embedded intelligent product development process
Basic operations of databases and tables ----- view data tables
FTP file upload file implementation, regularly scan folders to upload files in the specified format to the server, C language to realize FTP file upload details and code case implementation
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
ESP学习问题记录
Common properties of location
随机推荐
I2C总线时序详解
There are three iPhone se 2022 models in the Eurasian Economic Commission database
高通&MTK&麒麟 手机平台USB3.0方案对比
Basic operations of databases and tables ----- view data tables
C语言函数之可变参数原理:va_start、va_arg及va_end
Cannot change version of project facet Dynamic Web Module to 2.3.
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
map文件粗略分析
I2C bus timing explanation
Arduino JSON data information parsing
Arduino gets the length of the array
Principle and implementation of MySQL master-slave replication
R & D thinking 01 ----- classic of embedded intelligent product development process
Encodermappreduce notes
. elf . map . list . Hex file
ESP8266使用arduino连接阿里云物联网
JS正则表达式基础知识学习
MongoDB
互联网协议详解
Rough analysis of map file