当前位置:网站首页>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;
}
边栏推荐
- C language, log print file name, function name, line number, date and time
- 电商数据分析--薪资预测(线性回归)
- 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
- Arduino uno R3 register writing method (1) -- pin level state change
- Keyword inline (inline function) usage analysis [C language]
- Distribute wxWidgets application
- Dependency in dependencymanagement cannot be downloaded and red is reported
- Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
- Basic use of pytest
- 电商数据分析--用户行为分析
猜你喜欢
几个关于指针的声明【C语言】
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
电商数据分析--薪资预测(线性回归)
Principle and implementation of MySQL master-slave replication
ES6 grammar summary -- Part 2 (advanced part es6~es11)
优先级反转与死锁
Togglebutton realizes the effect of switching lights
锂电池基础知识
Machine learning -- decision tree (sklearn)
荣耀Magic 3Pro 充电架构分析
随机推荐
JS正则表达式基础知识学习
arduino JSON数据信息解析
Oppo vooc fast charging circuit and protocol
Dead loop in FreeRTOS task function
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
电商数据分析--用户行为分析
Basic operations of databases and tables ----- view data tables
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
Cannot change version of project facet Dynamic Web Module to 2.3.
gcc 编译选项
JS 函数提升和var变量的声明提升
C语言,log打印文件名、函数名、行号、日期时间
Contiki源码+原理+功能+编程+移植+驱动+网络(转)
Navigator object (determine browser type)
Linux Yum install MySQL
inline详细讲解【C语言】
Keyword inline (inline function) usage analysis [C language]
高通&MTK&麒麟 手机平台USB3.0方案对比
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
Kaggle competition two Sigma connect: rental listing inquiries