2021年5月27日 星期四

分組累積例 python list

 s = [int(i) for i in input().split()]


start = 0

end = 0


while end<len(s):

acc =0

while s[start]*s[end]>0 or s[start]==0 and s[end]==0:

acc+=s[end]

end+=1

if end >=len(s): break

end = end -1

if acc>0: print(start+1,end+1,end-start+1,acc)

start = end+1

end = end+1

acc = 0

沒有留言: