【PAT甲级】1081 Rational Sum (20 分)
题意:
输入一个正整数N(<=100),接着输入N个由两个整数和一个/组成的分数。输出N个分数的和。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[],b[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i){
cin>>a[i];
cin.ignore();
cin>>b[i];
int t=max(,__gcd(a[i],b[i]));
a[i]/=t;
b[i]/=t;
}
int ans=;
for(int i=;i<=n;++i){
int tamp=b[i-]*b[i];
int sum=a[i]*b[i-]+a[i-]*b[i];
int t=__gcd(tamp,sum);
tamp/=t;
sum/=t;
ans+=sum/tamp;
sum%=tamp;
a[i]=sum;
b[i]=tamp;
}
if(ans&&a[n])
cout<<ans<<" "<<a[n]<<"/"<<b[n];
else if(ans)
cout<<ans;
else if(a[n])
cout<<a[n]<<"/"<<b[n];
else
cout<<;
return ;
}
【PAT甲级】1081 Rational Sum (20 分)的更多相关文章
- PAT 甲级 1081 Rational Sum (数据不严谨 点名批评)
https://pintia.cn/problem-sets/994805342720868352/problems/994805386161274880 Given N rational numbe ...
- PAT Advanced 1081 Rational Sum (20) [数学问题-分数的四则运算]
题目 Given N rational numbers in the form "numerator/denominator", you are supposed to calcu ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)
1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is de ...
- PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
随机推荐
- spring boot使用freemarker模版整合spring Data JPA
目录结构 第一步:在pom.xml文件中添加依赖 <!--模板依赖--> <dependency> <groupId>org.springframework.boo ...
- DFT测试-OCC电路介绍
https://www.jianshu.com/p/f7a2bcaefb2e SCAN技术,也就是ATPG技术-- 测试std-logic, 主要实现工具是: 产生ATPG使用Mentor的 Test ...
- codeforces 1282C. Petya and Exam (贪心)
链接:https://codeforces.com/contest/1282/problem/C 题意: 有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a:另一种是困难题,每道题耗 ...
- android 代码设置图标背景色(圆形图标)和图标颜色
原图: 1.改变图标颜色: mImageView.setColorFilter(Color.parseColor("#ff0000")); 效果: 2.改变图标背景色(主要是圆形图 ...
- C++/CLI剪辑
1.本地类中包含托管类成员变量的情况 #include<vcclr.h> // 必须包含vcclr.h头文件 //传入 A^ a = gcnew A(); gcroot<A^> ...
- 每天进步一点点------Allegro手工建立电路板
手工建立电路板步骤(以某个四层板为例): (1)file---new---board/board wizard来建立.brd电路板文件.设置名称和保存路径后,要设置绘图区域的大小,setup---dr ...
- CSS-透明背景色兼容
IE 不支持透明背景色 使用fileter div{ backgournd: #666; filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5 ...
- Python偶斐波那契数
斐波那契数列中的每一项都是前两项的和.由1和2开始生成的斐波那契数列前10项为 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … 考虑该斐波那契数列中不超过四百万的项,求其中为 ...
- MomentJS记录下开发中用到的日期
1.计算当前周一到周日的日期 var weekOfday = moment().format('E');//计算今天是这周第几天 var last_monday = moment().s ...
- 欧拉函数-bzoj2818-简单推导
This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...