2018-12-26我的世界开始下雪*

2018-12-26  本文已影响0人  loucx
IMG_20181226_142330.jpg IMG_20181226_142358.jpg IMG_20181226_160134.jpg IMG_20181226_160148.jpg

今天早上天气就不怎么好,下午去回餐听张老师讲课时就突然开始下雪了,而且雪越下越大,等听完课出来,外面的景色已经可以用白雪皑皑来形容了。
晚上把MOOC上的一门课的考试做完了,还学了两种求最大公倍数的方法。
辗转相除法:

line1 = input()


def solution(line):
    list1 = line.split('/')
    zi = int(list1[0])
    mu = int(list1[1])
    bb = max(zi, mu)
    ss = min(zi, mu)
    r = 1
    while r != 0:
        r = bb % ss
        bb = ss
        ss = r
    zi = zi/bb
    mu = mu/bb
    return "{:.0f}/{:.0f}".format(zi, mu)


print(solution(line1))

辗转相减法(更相减损术):

line1 = input()


def solution(line):
    list1 = line.split('/')
    zi = int(list1[0])
    mu = int(list1[1])
    bb = max(zi, mu)
    ss = min(zi, mu)

    while bb % 2 == 0:
        bb = bb/2
    while ss % 2 == 0:
        ss = ss/2

    ji = ss
    mi = bb
    ji = mi - ji
    while ji != mi:

        ma = max(ji, mi)
        mi = min(ji, mi)
        ji = ma - mi

    zi = zi/mi
    mu = mu/mi
    return "{:.0f}/{:.0f}".format(zi, mu)


print(solution(line1))
上一篇下一篇

猜你喜欢

热点阅读