浙江大学PAT_甲级_1081. Rational Sum (20)

华为OD技术面真题 - JAVA开发 - 1 汇总华为OD技术面八股JAVA八股,高频技术真题并提供详细解答。 阅读详情

题目链接:点击打开链接

Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.

Input Specification:

Each input file contains one test case. Each case starts with a positive integer N (<=100), followed in the next line N rational numbers "a1/b1 a2/b2 ..." where all the numerators and denominators are in the range of "long int". If there is a negative number, then the sign must appear in front of the numerator.

Output Specification:

For each test case, output the sum in the simplest form "integer numerator/denominator" where "integer" is the integer part of the sum, "numerator" < "denominator", and the numerator and the denominator have no common factor. You must output only the fractional part if the integer part is 0.

Sample Input 1:
5
2/5 4/15 1/30 -2/60 8/3
Sample Output 1:
3 1/3
Sample Input 2:
2
4/3 2/3
Sample Output 2:
2
Sample Input 3:
3
1/3 -1/6 1/8
Sample Output 3:
7/24
我的C++

#include<iostream>
using namespace std;
long long greatest_common_divisor(long long a, long long b)//求最大公约数
{
	int r;
	while (b>0)
	{
		r = a%b;
		a = b;
		b = r;
	}
	return a;
}
int main()
{
	long long numerator, denominator, divisor;//分子,分母,最大公约数
	long long num_sum=0,den_sum=1;//和的分子,和的分母
	int n;
	cin >> n;
	while (n--)
	{
		scanf("%lld/%lld", &numerator, &denominator);
		num_sum = num_sum*denominator + den_sum*numerator;
		den_sum = den_sum*denominator;
		divisor = greatest_common_divisor(labs(num_sum), labs(den_sum));//最大公约数
		num_sum = num_sum / divisor;//约分
		den_sum = den_sum / divisor;//约分
	}
	if (num_sum == 0)//和等于0
	{
		printf("0");//直接输出
	}
	else//和不为零
	{
		if (num_sum / den_sum&& num_sum%den_sum)//带分数
		{
			cout << num_sum / den_sum<<' '<<num_sum%den_sum<<'/'<<den_sum;
		}
		else if (num_sum / den_sum != 0)//整数
		{
			cout << num_sum / den_sum;
		}
		else if (num_sum%den_sum != 0)//真分数
		{
			cout << num_sum << '/' << den_sum << endl;
		}

	}
	//system("pause");
	return 0;
}


SAP B1中文培訓教材_SDK 公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说 立即下载

相关推荐

别再只用线性回归了!用sklearn的核岭回归搞定非线性数据(附RBF核调参实战)

本文详细介绍了如何使用sklearn的核岭回归处理非线性数据,特别是RBF核的应用与调参实战。通过网格搜索找到最佳参数组合,核岭回归能有效捕捉数据中的复杂波动,显著提升模型性能。适合需要解决非线性问题的数据科学家和机器学习工程师。

weixin_34246529的博客 350

PAT Rational Sum

题目:https://www.nowcoder.com/pat/1/problem/4311题目描述:Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.输入描述:Each input file contains one test case. Ea...

Sharon0701的博客 309

基于Python适用于YOLO目标检测算法的图片数据增强处理

为了增强模型的鲁棒性以及数据的丰富性,同 时为了防止由于数据过少发生过拟合,本设计对数 据集进行数据增强处理,包括随机亮度调节、随机 对比度调节、随机饱和度调节、加入高斯噪声、水 平翻转、运动模糊和旋转 15°

weixin_67136409的博客 711

PAT 甲级 1081. Rational Sum (20)

Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positi

zengjingchao的博客 256

基于CNN的表情识别(FER)pytorch实现

Report for FER Jian Tang Abstract 我们使用卷积神经网络(CNN)实现了baby的面部表情识别(FER)。 数据上,我们获取了开源FER数据集FER2013[1],besides我们使用爬虫获取了baby相关的人脸图片,进行了手工分类标注以形成一个全新的baby FER数据集。 模型上,我们首先复现了Luan[2]的工作,即参考Kuo[3]在CVPR 2018上的工作并实现一个轻量的CNN网络,在FER2013上进行训练并得到了XXXX%的平均分类准确率(avg a

qq_20241587的博客 3692

innovus:ccopt_design流程

我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?spec文件可以只创建一次,无需多次创建。2)virtual balance阶段。3)Full Balancing阶段。4)Clock Routing阶段。1)clustering阶段。

m0_61544122的博客 2500

1081 Rational Sum (20 分)(数学题)

1081 Rational Sum (20 分) Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case sta...

virgilshi的博客 653

YOLOv8改进 | Conv篇 | DWRSeg扩张式残差助力小目标检测 (附修改后的C2f+Bottleneck)

本文内容给大家带来的DWRSeg中的DWR模块来改进YOLOv8中的C2f和Bottleneck模块,主要针对的是小目标检测,主要创新点可以总结如下:多尺度特征提取机制的深入研究和创新的DWR模块和SIR模块的提出这种方法使得网络能够更灵活地适应不同尺度的特征,从而更准确地识别和分割图像中的物体。通过本文你能够了解到DWRSeg的基本原理和框架,并且能够在你自己的网络结构中进行添加(DWRSeg需要增加一定的计算量一个DWR模块大概增加0.4GFLOPs)。

Snu77的博客 9586

PAT 1081. Rational Sum (20)

http://www.nowcoder.com/pat/1/problem/4311 挺简单的题目,但是卡了好久,主要太久没做手生了。 牢记最小公倍数的函数 注意负数情况的处理 最后的输出是有要求的 - #include<stdio.h> #include<iostream> #include<math.h>using namespace std;long long a[101],b[101];

悟已往之不谏,知来者之可追 453

软件产品国际化:前后端及App多语言版本解决方案(超详细实现过程)

多语言版本解决方案是应对全球化趋势的关键策略,它通过构建灵活且可扩展的架构,支持软件产品在不同语言和文化环境下的顺畅运行与展示。此方案涵盖了前端多语言界面实现、后端多语言数据处理及大数据环境下的多语言支持等多个层面,确保公司能够高效地推出适应全球用户多样化需求的软件产品。在前端多语言界面实现方面,解决方案采用了国际化与本地化的结合方法。国际化过程确保软件的功能和代码设计能够处理多种语言和文化习惯,而本地化则针对特定地区进行界面和内容的调整。

大模型大数据攻城狮的专栏 2771

sec_uid

webcast_uid转sec_uid,webcast_uid转uid,webcast_uid转dy号

m0_56967679的博客 4440

PAT A1081. Rational Sum (20)

Given N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive intege

哈哈菌 432

人工蜂鸟算法(AHA)详解:原理、实现与应用

人工蜂鸟算法(AHA)是一种受蜂鸟飞行技能和觅食策略启发的新型元启发式优化算法。该算法模拟蜂鸟的全向飞行、记忆能力和觅食行为,通过引导觅食、领地觅食和迁徙觅食三种策略在解空间高效搜索。AHA将优化问题解类比为食物源,蜂鸟作为搜索代理,利用访问表记录访问信息。算法核心包括三种飞行技能建模(全向、对角线和轴向飞行)以及对应的数学公式实现。Python实现展示了种群初始化、适应度计算和觅食行为模拟等关键步骤。AHA以其高效的全局搜索能力、良好收敛性和鲁棒性,在复杂优化问题中表现优异。

qq_42212808的博客 927

PAT甲级 1081 Rational Sum

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 186

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【PAT甲级A1081】Rational Sum (20分)(c++)

1081 Rational Sum (20分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:250 ms 内存限制:64 MB Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case st

小庄同学的博客 188

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【PAT】A1081. Rational Sum (20)

Author: CHEN, Yue Organization: 浙江大学 Time Limit: 400 ms Memory Limit: 64 MB Code Size Limit: 16 KB A1081. Rational Sum (20) Given N rational numbers in the form “numerator/denominator”, you are ...

Duke 313

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

1081. Rational Sum (20)-PAT甲级真题

1081. Rational Sum (20)Given N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case s...

柳婼 の blog 2856

*浙大PAT甲级 1081

题目不难,但是需要注意的细节很多,尤其是 long long虽然数的范围在int内,但是求最小公倍数时,相乘会超出int范围,因此用long long; AC代码: #include #include #include #include #include #include #include #include #include #include #include #define inf 9999

威的博客 509

1081. Rational Sum (20)

题目链接:http://www.patest.cn/contests/pat-a-practise/1081 题目: Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum. Input Specification: Each

Apie_CZX的专栏 5012

1081. Rational Sum (20)-PAT甲级

题目:Given N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case starts with a positiv

ZZLCSDN2017的博客 685

《PTA——拼题A》之第1081题

题目介绍 本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点.,还必须既有字母也有数字。 输入格式: 输入第一行给出一个正整数 N(≤ 100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。 输出格式: 对每个用户的密码,在一行中输出系统反馈信...

Adward_Z的博客 2504

浙江大学PAT_甲级_1094. The Largest Generation (25)

题目链接:点击打开链接 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest po

~~(v_v)~~ 1240

PAT_甲级_1001. A+B Format (20)

1001. A+B Format (20)   Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input...

~~(v_v)~~ 1172

浙江大学PAT_甲级_1005.1005. Spell It Right (20)

c++实现

~~(v_v)~~ 991

浙江大学PAT_甲级_1032. Sharing (25)

题目地址:点击打开链接 To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suf

~~(v_v)~~ 778

PAT_甲级_1029. Median (25)

题目链接:点击打开链接   Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16...

~~(v_v)~~ 746
上一篇: Android App更改背景颜色
下一篇: Android App添加按钮事件
pythontojava
博客等级 码龄12年 84粉丝 140原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址