题解 | #汽水瓶#

汽水瓶

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

#本题主要考查递归算法
def bottle_num(n):
    res = n//3
    remain = n%3
    bottles = res+remain    #the bottle number of remain
    if bottles == 2: #permit borrow one bottle
        res+=1
    elif bottles < 2:   #the bottle number is not ample
        pass
    else:
        res = res + bottle_num(bottles) #bottle>2,start digui algrithm
    return res

while 1:#use while accomplishment a lot of input
    n = int(input())
    if n == 0:
        break
    else:
        print(bottle_num(n))

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 17:30
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务