• PAT (Advanced Level) Practice 1088 Rational Arithmetic (20分)


    1.题目

    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 one line the two rational numbers in the format a1/b1 a2/b2. The numerators and the denominators are all in the range of long int. If there is a negative sign, it must appear only in front of the numerator. The denominators are guaranteed to be non-zero numbers.

    Output Specification:

    For each test case, print in 4 lines the sum, difference, product and quotient of the two rational numbers, respectively. The format of each line is number1 operator number2 = result. Notice that all the rational numbers must be in their simplest form k a/b, where k is the integer part, and a/b is the simplest fraction part. If the number is negative, it must be included in a pair of parentheses. If the denominator in the division is zero, output Inf as the result. It is guaranteed that all the output integers are in the range of long int.

    Sample Input 1:

    2/3 -4/2
    

    Sample Output 1:

    2/3 + (-2) = (-1 1/3)
    2/3 - (-2) = 2 2/3
    2/3 * (-2) = (-1 1/3)
    2/3 / (-2) = (-1/3)
    

    Sample Input 2:

    5/3 0/6
    

    Sample Output 2:

    1 2/3 + 0 = 1 2/3
    1 2/3 - 0 = 1 2/3
    1 2/3 * 0 = 0
    1 2/3 / 0 = Inf

    2.代码

    PAT (Basic Level) Practice 1034 有理数四则运算 (20分)

  • 相关阅读:
    Pycharm如何自动换行
    Android逆向基础
    动态调试ELF文件Crackme
    用Hash 算法给payload瘦身
    010 editor手写pe文件
    win脱壳_压缩壳_aspack
    WannaCrypt0r分析报告
    JVM内存分区
    java设计模式(模板方法模式)
    es6
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788835.html
Copyright © 2020-2023  润新知