循环输入处理多个case
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
def bottle(nbot):
tmp=0
if nbot==1:
return 0
if nbot==2:
return 1
if nbot>=3:
while nbot>=3:
nwat = nbot // 3
nbot = nbot%3
nbot = nbot+nwat
tmp += nwat
if nbot==2:
return tmp+1
else:
return tmp
if __name__=="__main__":
#bot = int(input())
while True:
bot=sys.stdin.readline().strip()
if not bot :
break
bot=int(bot)
bottles=bottle(bot)
print(bottles)
一开始,本地调试一直没有问题,但是提交之后总是显示输出为空,原因为没有对多行输入进行处理。
if __name__=="__main__":
#bot = int(input())
bot=sys.stdin.readline().strip()
bot=int(bot)
bottles=bottle(bot)
print(bottles)