简单模拟题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std; struct FenShu
{
long long fz,fm;
FenShu(long long a,long long b)
{
fz=a;
fm=b;
}
}; long long gcd(long long a,long long b)
{
if(b==) return a;
return gcd(b,a%b);
} FenShu ADD(FenShu a,FenShu b)
{
FenShu res(,);
res.fz=a.fz*b.fm+b.fz*a.fm;
res.fm=a.fm*b.fm; if(res.fz!=)
{
long long GCD=gcd(abs(res.fz),abs(res.fm));
res.fz=res.fz/GCD;
res.fm=res.fm/GCD;
}
else
{
res.fz=;
res.fm=;
}
return res;
} int main()
{
int n; scanf("%d",&n);
FenShu ans(,);
for(int i=;i<=n;i++)
{
long long fz,fm; scanf("%lld/%lld",&fz,&fm);
FenShu t(fz,fm);
ans=ADD(ans,t);
}
//printf("%d/%d\n",ans.fz,ans.fm);
if(ans.fz==) printf("0\n");
else
{
if(ans.fz%ans.fm==) printf("%lld\n",ans.fz/ans.fm);
else if(abs(ans.fz)<ans.fm) printf("%lld/%lld\n",ans.fz,ans.fm);
else
{
long long d=ans.fz/ans.fm;
ans.fz=ans.fz-d*ans.fm;
printf("%lld %lld/%lld\n",d,ans.fz,ans.fm);
}
}
return ;
}

PAT (Advanced Level) 1081. Rational Sum (20)的更多相关文章

  1. 【PAT甲级】1081 Rational Sum (20 分)

    题意: 输入一个正整数N(<=100),接着输入N个由两个整数和一个/组成的分数.输出N个分数的和. AAAAAccepted code: #define HAVE_STRUCT_TIMESPE ...

  2. PAT (Advanced Level) 1088. Rational Arithmetic (20)

    简单题. 注意:读入的分数可能不是最简的.输出时也需要转换成最简. #include<cstdio> #include<cstring> #include<cmath&g ...

  3. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  4. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

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

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

  6. PAT甲题题解-1081. Rational Sum (20)-模拟分数计算

    模拟计算一些分数的和,结果以带分数的形式输出注意一些细节即可 #include <iostream> #include <cstdio> #include <algori ...

  7. 1081. Rational Sum (20)

    the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1081 the code ...

  8. 1081. Rational Sum (20) -最大公约数

    题目如下: Given N rational numbers in the form "numerator/denominator", you are supposed to ca ...

  9. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

随机推荐

  1. git简单使用教程

    git 的基本使用指令 我们先来简单熟悉一下 git 的简单使用的指令, 作为最基本的 git 指令一定要熟悉 12345678910111213141516171819202122232425262 ...

  2. 有了SSL证书,如何在IIS环境下部署https?【转载】

    昨天各位小伙伴都很开心的领取了自己的SSL证书,但是大部分小伙伴却不知道如何部署,也许是因为第一次接触SSL这种高端的东西吧,不过个人觉得就是懒懒懒...本来小编也挺懒的,但是答应了各位小伙伴的,那么 ...

  3. JSP基础语法--跳转指令 jsp:forward page

    带参数的跳转指令: <jsp:forward page="{路径|<%=表达式%>}"/> <jsp:param name="参数名称&qu ...

  4. SSH自动断开连接的原因

    方法一: 用putty/SecureCRT连续3分钟左右没有输入, 就自动断开, 然后必须重新登陆, 很麻烦. 在网上查了很多资料, 发现原因有多种, 环境变量TMOUT引起,ClientAliveC ...

  5. mongodb启动

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可护展的高性能数据存储解决方案.MongoDB是一款分布式文档数据库,支持类似关型数据库的主从结构,文档以二进制J ...

  6. git 更新分支

    git branch  本地分支 git branch test 创建分支 git pull origin fastboot 更新到最新版本 git branch -a  查看所有的分支,包括本地的和 ...

  7. IOS 中常用站位符

      CGPoint.CGRect等可以转化为字符串打印出来 如:   NSLog(@"-------------%@",NSStringFromCGPoint(point));   ...

  8. sql查询百分号的方法

    select * from [tablename] where [col] like '%100/%%' escape '/'

  9. 使用VS软件打开网站在浏览器浏览的方法

    1.用VS软件打开网站之后,先检查网站是否使用IIS Express开发 2.若不是,则切换成使用IIS Express开发 3.检查项目使用的托管管道模式设置为经典模式了没有 4.最后选择“在浏览器 ...

  10. Css 之 px em %

    在页面整体布局中,页面元素的尺寸大小(长度.宽度.内外边距等)和页面字体的大小也是重要的工作之一.一个合理设置,则会让页面看起来层次分明,重点鲜明,赏心悦目.反之,一个不友好的页面尺寸和字体大小设置, ...