根据Neyanbhbin以及变戏法的羊的解答,我最终将程序修改如下,并通过: import sys lines = [] for line in sys.stdin: a=int(line) if a!=0: lines.append(a) lenLine = len(lines) def MaxBottleNum(Num): rest = (Num%3) n = (Num//3) New_Num = n + rest while((New_Num)>=3): n +=(New_Num//3) rest1 = New_Num%3 New_Num = rest1 + (New_Num//3) if New_Num == 2: n += 1 return n for i in range(lenLine): num = lines[i] print(MaxBottleNum(num))
牛客网
牛客企业服务