public
Authored by
EC2 Bot

周沙曈-单元测验前-分数相加

6ed5e16018c6527a9f66d5aa565beb9f.ec2 529 bytes
# 假定 a1, b1, a2, b2 均为正整数
算始 分数相加 (a1, b1, a2, b2)
    a1 := 整数(a1)
    b1 := 整数(b1)
    a2 := 整数(a2)
    b2 := 整数(b2)
    
    a := a1 * b2 + a2 * b1
    b := b1 * b2

    n := 0          # 整数部分
    若始 (a > b)
        n := a // b
        a := a % b
    若终

    # 求最大公约数
    x := a; y := b
    当始 (y != 0)
        tmp := x
        x := y
        y := tmp % y
    当终

    a := a // x
    b := b // x

    输出 (n)
    输出 (a)
    输出 (b)
算终
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment