题解 | #汽水瓶#
汽水瓶
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))