当前位置:网站首页>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)
边栏推荐
- Setinterval, setTimeout and requestanimationframe
- Machine learning project captcha based on verification code recognition_ Trainer operation practice
- 使用logrotate对宝塔的网站日志进行自动切割
- On the output representation of bidirectional LSTM in pytoch
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
- Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
- mysql-.sql文件钓鱼上线
- For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
- day23 js笔记 2021.09.14
- Xshell and xftp tutorial
猜你喜欢

Making and using of dynamic library (shared library)

Web page tips this site is unsafe solution

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

Industry analysis - quick intercom, building intercom

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

太阳能无线LED显示屏的特点

Fancy features and cheap prices! What is the true strength of Changan's new SUV?

Jetpack Compose Desktop 桌面版本的打包和发布应用

QML控件类型:TabBar

Scientific research - web of science retrieval skills
随机推荐
day39 原型链及页面烟花效果 2021.10.13
String & heap & method area
Industry analysis - quick intercom, building intercom
day23 js笔记 2021.09.14
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush
TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
day39 原型鏈及頁面烟花效果 2021.10.13
Unity屏幕截图功能
来吧元宇宙,果然这热度一时半会儿过不去了
js中的数组方法 2021.09.18
GCC introduction
Making and using of static library
使用logrotate对宝塔的网站日志进行自动切割
MySQL cannot query the maximum value using the max function
Splicing strings in the string collection_ Stream based
Setinterval, setTimeout and requestanimationframe
Remote login sshd service
On the output representation of bidirectional LSTM in pytoch
Day39 prototype chain and page fireworks effect 2021.10.13
Redis6 一:Nosql引入、Redis可以解决什么问题?