当前位置:网站首页>5. Sum of N numbers
5. Sum of N numbers
2022-06-28 11:46:00 【HBUcs2020】
#include<iostream>
using namespace std;
#include<algorithm>
/*int GCD(int a,int b)
{
if(b==0)
return a;
else
return GCD(b,a%b);
}*/
int main()
{
int n,a,b,nume,deno,divisor;
scanf("%d%d/%d",&n,&nume,&deno);
for(int i=1;i<n;i++)
{
scanf("%d/%d",&a,&b);
nume=nume*b+a*deno;
deno=deno*b;
divisor=__gcd(nume,deno);
nume=nume/divisor;
deno=deno/divisor;
}
/* if(deno<0)
{
deno=-deno;
nume=-nume;
}*/
// There are molecules on it / The form of denominator , May be 1/1 This integer form , May be 1/5 This fraction form , special 0/8 This is an integer , also 5/3 such
if(nume&&nume/deno==0) // For the score // Note that the molecules are not 0 And molecules / The denominator is 0, So the number is a fraction
printf("%d/%d",nume,deno);
else if(nume%deno==0) // Only integer
printf("%d\n",nume/deno);
else
printf("%d %d/%d\n",nume/deno,nume%deno,deno);
return 0;
}
special 0/8 This is an integer
if(nume&&nume/deno==0)
边栏推荐
- Lihongyi, machine learning 7 Conclusion
- Gee: mcd64a1 based globfire daily fire data set
- 使用logrotate对宝塔的网站日志进行自动切割
- day39 原型链及页面烟花效果 2021.10.13
- Day36 JS notes ecma6 syntax 2021.10.09
- mysql-. SQL file phishing Online
- 一套十万级TPS的IM综合消息系统的架构实践与思考
- 来吧元宇宙,果然这热度一时半会儿过不去了
- 智联招聘基于 Nebula Graph 的推荐实践分享
- Jetpack Compose Desktop 桌面版本的打包和发布应用
猜你喜欢

Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community

Day39 prototype chain and page Fireworks Effect 2021.10.13

网页提示此站点不安全解决方案

QML控件类型:TabBar

如临现场的视觉感染力,NBA决赛直播还能这样看?

一套十万级TPS的IM综合消息系统的架构实践与思考

Deployment and optimization of vsftpd service

Industry analysis - quick intercom, building intercom

Array method in JS 2021.09.18

行业分析| 快对讲,楼宇对讲
随机推荐
人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
What is the main chain system?
Intranet penetration in the working group environment: some basic methods
基于验证码识别的机器学习项目captcha_trainer操作实践
【无标题】虚拟机vmnet0找不到且报错:没有未桥接的主机网络适配器
功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?
Unity屏幕截图功能
JS foundation 10
2022中国信通院首届业务与应用安全发展论坛成功召开!
Create ECS using API shortcut
如临现场的视觉感染力,NBA决赛直播还能这样看?
Splicing strings in the string collection_ Stream based
工作组环境下的内网渗透:一些基础打法
Jetpack Compose Desktop 桌面版本的打包和发布应用
Scientific research - web of science retrieval skills
day36 js笔记 ECMA6语法 2021.10.09
Calculate time using calendar
使用logrotate对宝塔的网站日志进行自动切割
day30 js笔记 BOM和DOM 2021.09.24
mysql-.sql文件钓鱼上线