导入itertools之后,我在下面的代码上运行itertools.accumulate(),并且出现错误提示-
Traceback (most recent call last):
File "Equal_Stacks.py", line 36, in <module>
result = equalStacks(h1 , h2 , h3)
File "Equal_Stacks.py", line 8, in equalStacks
h11 = itertools.accumulate(h1)
AttributeError: 'module' object has no attribute 'accumulate'
但是当我在解释器中运行itertools.accumulate()函数时,它就可以正常工作。
import sys
import itertools
def equalStacks(h1 , h2 , h3):
h11 = itertools.accumulate(h1)
h22 = itertools.accumulate(h2)
h33 = itertools.accumulate(h3)
equal = False
while not equal:
if h11[-1] == h22[-1] == h33[-1]:
equal = True
break
else:
if h11[-1] > h22[-1] and h11[-1] > h33[-1] and len(h11) != 0:
h11.pop()
elif h22[-1] > h11[-1] and h22[-1] > h33[-1] and len(h22) != 0:
h22.pop()
elif h33[-1] > h11[-1] and h33[-1] > h22[-1] and len(h33) != 0:
h33.pop()
return str(h11[-1])
if __name__ == '__main__':
n1 , n2 , n3 = map( int , sys.stdin.readline().strip().split() )
h1 = list( map( int, sys.stdin.readline().strip().split() ) )
h2 = list( map( int, sys.stdin.readline().strip().split() ) )
h3 = list( map( int, sys.stdin.readline().strip().split() ) )
result = equalStacks(h1 , h2 , h3)
_ = sys.stdout.write( result + '\n')