题意:

输入一个正整数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 分)的更多相关文章

  1. PAT 甲级 1081 Rational Sum (数据不严谨 点名批评)

    https://pintia.cn/problem-sets/994805342720868352/problems/994805386161274880 Given N rational numbe ...

  2. PAT Advanced 1081 Rational Sum (20) [数学问题-分数的四则运算]

    题目 Given N rational numbers in the form "numerator/denominator", you are supposed to calcu ...

  3. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  4. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  5. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  6. PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)

    1046 Shortest Distance (20 分)   The task is really simple: given N exits on a highway which forms a ...

  7. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  8. PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

    1041 Be Unique (20 分)   Being unique is so important to people on Mars that even their lottery is de ...

  9. PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

    1015 Reversible Primes (20 分)   A reversible prime in any number system is a prime whose "rever ...

随机推荐

  1. Tomcat 加载外部dll时如何配置

    1.在myeclipse环境下配置 先将dll放置在c:\windows\system32中,然后在myEclipse中,window->Preferences->MyEclipse-&g ...

  2. jsonp实现js跨域请求

    sonp是跨域通信的一个协议 具体来说jsonp实现跨域请求其实是使用js文件引用(js文件不一定是.js结尾)可跨域的性质,将请求的结果包裹在客户端需要调用的js方法内部.需要前后端配合使用. 前段 ...

  3. js解释器

    又名js引擎 JavaScript是解释型语言,这就是说它无需编译,直接由JavaScript引擎直接执行. 既然说到了解释型语言,那么我们就来分别以下解释型语言和编译型语言的差别: 编译型语言:程序 ...

  4. access denied (2)

    除了https://www.cnblogs.com/bneglect/p/11558593.html  这里提到的以外,今天再记录一个新的原因造成这种情况的解决方法.path_info 这个算是路由模 ...

  5. 牛客多校第三场F Planting Trees 单调栈

    Planting Trees 题意 给出一个矩阵,求最大矩阵面积满足该矩阵中任2元素的绝对值之差小于等于M T<1000) (n<500)但是题目明示单组(n*3)可过 分析 又是矩阵问题 ...

  6. CentOS7网络配置:静态IP和DHCP

    1.打开并编辑网络配置文件:/etc/sysconfig/network-scripts/ifcfg-ens33 [root@localhost network-scripts]# vim ifcfg ...

  7. 转载:DRC

    https://cn.mathworks.com/help/audio/ug/dynamic-range-control.html?requestedDomain=cn.mathworks.com h ...

  8. 【C语言】用C语言输出“心形”图案

    在你们的世界里,是不是觉得程序猿一点浪漫都不懂?其实不是的,程序猿的世界也是很浪漫滴! 傻瓜版 int main() { printf("❤"); ; } 高级版 //版本一:单个 ...

  9. Python出现Could not find a version that satisfies the requirement openpyxl (from versions: )

    一.环境使用python3.7时,用pip安装openpyxl出现如下错误: 系统环境:windows10家庭版Python版本:python3.7.1IDE:sublime_text 3二. 解决方 ...

  10. summernote 上传图片到图片服务器的解决方案(springboot 成功)

    遇到的可以连接成功但是拒绝登录的问题 前提说一下,我自己在自己的服务器上配置了nginx的反向代理,所以请求的时候才会直接写的是我的ip地址,要配置nginx的话,可以看我的nginx的笔记 当代码感 ...