当前位置:网站首页>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;
}
边栏推荐
- 高通&MTK&麒麟 手机平台USB3.0方案对比
- arduino JSON数据信息解析
- Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
- 【ESP32学习-1】Arduino ESP32开发环境搭建
- [esp32 learning-1] construction of Arduino esp32 development environment
- 物联网系统框架学习
- GNN的第一个简单案例:Cora分类
- VSCode基础配置
- The first simple case of GNN: Cora classification
- Amba, ahb, APB, Axi Understanding
猜你喜欢

E-commerce data analysis -- salary prediction (linear regression)

AMBA、AHB、APB、AXI的理解

ESP学习问题记录

RT-Thread的main线程“卡死”的一种可能原因及解决方案

I2C bus timing explanation

Linux Yum install MySQL
![[esp32 learning-1] construction of Arduino esp32 development environment](/img/31/dc16f776b7a95a08d177b1fd8856b8.png)
[esp32 learning-1] construction of Arduino esp32 development environment

共用体(union)详解【C语言】

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

Vert. x: A simple TCP client and server demo
随机推荐
Detailed explanation of Union [C language]
OSPF message details - LSA overview
VSCode基础配置
I2C bus timing explanation
.elf .map .list .hex文件
关键字 inline (内联函数)用法解析【C语言】
C语言,log打印文件名、函数名、行号、日期时间
Vscode basic configuration
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
Embedded startup process
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
列表的使用
vim命令行笔记
JS正则表达式基础知识学习
ESP8266通过arduino IED连接巴法云(TCP创客云)
Selective sorting and bubble sorting [C language]
arduino JSON数据信息解析
Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
sklearn之feature_extraction.text.CountVectorizer / TfidVectorizer
5G工作原理详解(解释&图解)