题解 | #汽水瓶#

汽水瓶

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))

全部评论

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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