乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过 5050。
现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。
给出每段小木棍的长度,编程帮他找出原始木棍的最小可能长度。
乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过 5050。
现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。
给出每段小木棍的长度,编程帮他找出原始木棍的最小可能长度。

代码
#!/sur/bin/nve python
# coding: utf-8
def findLong(lis):
count = sum(lis)
factors = [i for i in range(1, int(count/min(lis))+1) if (not count%i) and count/i >= max(lis)]
return count/factors[-1]
if __name__ == '__main__':
text = '''
9
5 2 1 5 2 1 5 2 1'''
text2 = '''
5
2 2 2 2 2'''
text3 = '''
7
6 8 1 2 5 2 9'''
print(findLong(list(map(float, text.split('\n')[-1].split()))))
先前的不妥题解——


代码
#!/sur/bin/nve python
# coding: utf-8
def recount(nums):
nums = tuple(map(float, nums))
count = sum(nums)
if count < 50 or max(nums) > 50 :
print(' 输入错误!'.center(35, '~'))
exit()
n = count//50
count %= 50
return n, 50+count/n
if __name__ == '__main__':
result = recount(input(f"\n输入所有小木棍长度(如5 8 4.5 32.95 42):\n\n{'':>6}_").strip().split())
print(f"\n输出:\n\n{f'原有{result[0]:.0f}根{result[-1]:.2f}木棍':~^35}")