A1088 Rational Arithmetic (20) 分数的四则运算

java小练习(实现分数的四则运算) /* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称: * 作 者: 臧鹏 * 完成日期: 2012 年 9月 16日 * 版 本 号: 阅读详情

注意到每组都有类似的输出,所以最好还是写一个输出函数,除法的时候做判断是因为相除需要避免分母为负数。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=110;
struct node
{
   long long  up,down;
}n,m;
long long gcd(long long a,long long b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
void P(long long a,long long b)
{
   long long t=gcd(abs(a),b);
   a=a/t;
   b=b/t;
   if(a<0)
   printf("(");
   if(b==1)
   printf("%lld",a);
   else if(abs(a)>b)
   printf("%lld %lld/%lld",a/b,abs(a)%b,b);
   else
   printf("%lld/%lld",a,b);
   if(a<0)
   printf(")");
}
int main()
{
    scanf("%lld/%lld",&n.up,&n.down);
    scanf("%lld/%lld",&m.up,&m.down);
    P(n.up,n.down);printf(" + "); P(m.up,m.down);printf(" = "); P(n.up*m.down+n.down*m.up,n.down*m.down);printf("\n");
    P(n.up,n.down);printf(" - "); P(m.up,m.down);printf(" = "); P(n.up*m.down-n.down*m.up,n.down*m.down);printf("\n");
    P(n.up,n.down);printf(" * "); P(m.up,m.down);printf(" = ");
    if(n.up*m.up==0)printf("0");
    else P(n.up*m.up,n.down*m.down);
    printf("\n");
    P(n.up,n.down);printf(" / "); P(m.up,m.down);printf(" = ");
    if(m.up==0)printf("Inf");
    else if(n.down*m.up<0)P(-1*n.up*m.down,-1*n.down*m.up);
    else P(n.up*m.down,n.down*m.up);
    printf("\n");
}

用Python实现斗地主游戏(终端版) 马上就要过年了 大家也都放假了吧 过年必不可少的活动 打牌! 今天带大家来写一份斗地主 (又是好多天没怎么更新,忙成狗啊) 那么实现一个斗地主呢 我们肯定要先完善卡牌系统 from collections import Counter import numpy as np import itertools def cmp_to_key(mycmp): 'Convert a cmp= function into a key= function' class K: def _ 阅读详情

相关推荐

从想法到零件:手把手拆解一个汽车功能如何从PRD写到SSTS和CTS

本文详细拆解了汽车电子需求从市场文档(MRD)到零部件技术规范(CTS)的完整流程,以雨天自动关窗功能为例,展示了PRD、SSTS和CTS的编写要点与交互设计。文章重点解析了系统分解的艺术和零部件落地的精确参数要求,为汽车电子工程师提供了从概念到实现的全流程实践指南。

weixin_30300225的博客 481

A1088 Rational Arithmetic(分数四则运算-模板题)

题目描述 题目很简单,就是针对分数的四则运算输出结果,代码也很容易理解,注意一些细节容易出错: 1.分数化简,涉及到最大公约数 2.负数的表示 3.带分数的形式输出 分数的四则运算理解这道例题就足够了 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll gcd...

弋墨尘的博客 244

MiFlash Prime免授权刷机实战:解锁小米9008 EDL救砖新方案

MiFlash Prime作为免授权刷机工具,有效解决了小米设备在9008 EDL模式下因账号验证无法救砖的难题。本文详细介绍了从驱动安装、进入EDL模式到固件刷写的完整流程,帮助用户安全快速地恢复变砖设备,是维修人员和极客的实用解决方案。

5f4d3s2a1q的博客 2913

A1088 Rational Arithmetic (20 分)

做起来确实很长,注意全部要用long long,否则很多测试点通不过。 #include&lt;cstdio&gt; #include&lt;algorithm&gt; using namespace std; int gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b,a%b); } struct f...

A_Aria的博客 631

研究生如何快速发CVPR

研究生如何快速发CVPR,找到科研方向

python_vb的博客 787

嵌入式SPI总线抽象设计:跨平台驱动与分层解耦实践

SPI(串行外设接口)是嵌入式系统中应用最广泛的同步串行通信协议,其核心价值在于高吞吐、低开销与硬件简洁性。其工作原理基于主从架构、全双工/半双工时序及片选(CS)控制,依赖CPOL/CPHA组合定义四种标准模式。在工程实践中,SPI常面临硬件资源受限、多外设共用总线、MCU平台迁移等挑战,导致驱动复用率低、维护成本高。通过结构体+函数指针实现的分层抽象——将物理总线、协议适配与设备驱动解耦,可显著提升代码可移植性与扩展性。该方法天然支持硬件SPI与GPIO模拟SPI双模式切换,并已在STM32等主流MCU

weixin_42601134的博客 64

有理数类Rational实例

public class Rational extends Number implements Comparable { private long numerator=0; private long denominator=1; public Rational() { this(0,1); } public Rational(long numerator,long denomina

leafinsnowfield的专栏 2470

光学传播仿真软件:SPEOS_(14).建筑物内光环境仿真

在建筑物内光环境仿真中,材料属性的定义直接影响光的传播和反射效果。SPEOS提供了丰富的材料库,但也可以自定义材料属性以满足特定需求。创建新材料选择Materials->。输入材料名称和类型。配置材料属性选择材料对象,打开属性编辑器。设置反射率、透射率、表面粗糙度和颜色。# 导入SPEOS模块# 创建新材料# 配置材料属性custom_material.set_reflectivity(0.8) # 设置反射率为0.8。

kkchenjj的博客 1251

【PAT】A1088 Rational Arithmetic (20分)(分数的四则运算(全))

1088 Rational Arithmetic (20分) 题目链接 #include<iostream> #include<cmath> using namespace std; #include<cstdlib> typedef long long ll; struct Fraction{ ll up; ll down; }fraction[2]...

醉酒诗人的博客 256

Machine Unlearning: A Survey

机器学习已经引起了广泛的关注,并发展成为一种使能技术,用于广泛的高度成功的应用,如智能计算机视觉、语音识别、医疗诊断等。然而,由于隐私、可用性和/或被遗忘权,一些特定样本的信息需要从称为机器遗忘的模型中删除,这就产生了一种特殊的需求。这项新兴技术因其创新性和实用性而引起了学术界和工业界的极大兴趣。与此同时,这个雄心勃勃的问题导致了许多旨在应对其挑战的研究工作。据我们所知,没有任何研究分析过这一复杂的主题,也没有比较过现有的遗忘解决方案在不同场景下的可行性。因此,通过这项调查,我们旨在了解遗忘技术的关键概念。

c_cpp_csharp的专栏 1159

【国产MCU系列】-GD32F4开发环境搭建(基于Embedded Builder)

GD32F4系列MCU采用Arm® Cortex®-M4内核,处理器主频高达240MHz,可支持算法复杂度更高的嵌入式应用,具备更快速的实时处理能力,并拥有业界领先的大容量存储优势。

视觉与物联智能 3083

PAT (Advanced Level) Practice A1088 Rational Arithmetic (20 分)(C++)(甲级)(分数四则运算)

1088 Rational Arithmetic (20 分) For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Specification: Each ...

izhxxx的博客 206

C#上位机3D可视化:HelixToolkit.Wpf集成点云/模型(机器人臂姿态实时监控)

核心控件是3D可视化的核心,需搭配和网格辅助定位;模型加载:按关节拆分机械臂模型,通过组合平移+旋转实现姿态控制;姿态更新:将机器人关节角度转换为3D模型的旋转变换,工业场景需从控制器实时获取角度;点云渲染:通过实现点云加载,需注意坐标系转换和性能优化。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 717

1088. Rational Arithmetic (20)-PAT甲级真题

1088. Rational Arithmetic (20)For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Specification: Each ...

柳婼 の blog 2466

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PAT A1088 Rational Arithmetic (20 分) 有理数

题目大意:给出两个有理数,输出它们四则运算的结果,以最简带分数表示,分母为0的输出Inf。 与PAT A1081 Rational Sum类似,只是这里要求更多,需要进行四则运算。运算过程没有什么难度,有一个坑点是,尽管题目声明最终输出的数不会超过 long int 也就是 int 的范围,但是在运算过程中用 int 型可能会溢出,测试点2和3的浮点错误就是来源于此。所以有理数要...

HackingGate的博客 430

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

1088 Rational Arithmetic (20)

【代码】1088 Rational Arithmetic (20)

2401_88085478的博客 1610

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

甲级PAT 1088 Rational Arithmetic (20 分)(分数四则运算)

1088 Rational Arithmetic (20 分) For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Specification: Ea...

Joyceyang_999的博客 372

1088 Rational Arithmetic (20分)【分数的四则运算】

1088Rational Arithmetic(20分) For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Specification: Eac...

胡小涛的博客 230

A1088.Rational Arithmetic

A1088.Rational Arithmetic 题意 模拟分数的四则运算 思路分析 模拟,在输出过程中,若分子&gt;分母,需要分离出整数部分与分数部分,并且如果项为负数需要带上() #include &lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; struct...

chenming092100的博客 236

1088. Rational Arithmetic (20)[逻辑题]

1. 原题: https://www.patest.cn/contests/pat-a-practise/1088 2. 思路: 题意:既定格式的四则运算。基本逻辑题。 思路: 题意不难,但是要分情况,考察细节。 要点:整数要用长整型,分情况讨论就好了。 已AC。 3. 源码: #include #include using namespace std; typedef

坚不萌 421

A1088 Rational Arithmetic [分数四则运算]

#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } struct fraction { ll up, down; }f1,f2; fraction simplify(fr.

_计算机好苦 174

PAT A1088 Rational Arithmetic (20分)

前言 传送门 正文 参考题解 #include<iostream> using namespace std; /* 题意: 有理数的四则运算,其实就是分数的四则运算,和A1081的和 思路: 首先挂出三个函数模板,一是求最大公约数,二是化简函数reduction, 三是输出函数showRes(一般输出形式是 整数部分+真分数部分) */ //分数用结构体表示 typedef long long LL; struct Fraction{ LL up,down; }; //求最大公约数 L

逝不等琴生的博客 305

1088 Rational Arithmetic

题目来源:PAT (Advanced Level) Practice For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. Input Specification: Each input file contains one test case, which gives in

weixin_51032998的博客 189

PAT A 1088 Rational Arithmetic (20 分)

### 一、思路 构造输出函数,格式化输出分数: 1、分子或分母为零,输出0或Inf且不再进行其他处理 2、若分子分母均非零,将格式统一为分子分母均为正数,符号单独存储输出 3、输出分数: (1)若有整数部分,输出整数 (2)若有整数部分且有分数部分,输出空格 (3)若有分数部分,输出分数 ```python void output(long long a, long long b) { if( !b || !a ) { printf("%s", !b ? "Inf":"0"); return

Siumai's Blog 420

1088. Rational Arithmetic (20)

时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, pr...

SourDumplings的博客 456
上一篇: A1081 Rational Sum (20) 分数的四则运算
下一篇: B1013 数素数 (20) 素数 埃式筛法
coder_Kim
博客等级 码龄8年 2粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值