题解 | #汽水瓶#

汽水瓶

https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

# 不知如何简化步骤
def bottle(n: int):
    borrow = 0
    drink = int(n / 3)
    left = int(n % 3)

    if n < 2:
        drink = 0
    if drink + left == 2:
        borrow += 1
        # return drink
    if n > 3:
        drink += bottle(drink + left + borrow)
    return drink


if __name__ == "__main__":
    info = list()
    while True:
        try:
            tmp = int(input())
            info.append(tmp)
            if tmp == 0:
                break
        except:
            break
    validinfo = info[:-1]  # 去掉0
    for i in range(len(validinfo)):
        tmpn = bottle(validinfo[i])
        print(tmpn)

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务