本帖最后由 阴阳神万物主 于 2020-2-4 21:07 编辑
从格式上与他人做区别。def solve(s:'str of int')->bool:
def num(a,b):
while True:
yield a+b
a,b = b,a+b
le = len(s)
for l in range(1,(le//2)+1):
for r in range(1,le-l):
if r>1 and s[l] == '0':
break
n = iter(num(int(s[:l]),int(s[l:l+r])))
get = s[:l+r]
t = 2
while len(get)<=le:
if get == s and t>=3:
return True
get += str(next(n))
t += 1
return False
if __name__ == '__main__':
print('示例1 输出:',solve('112358'))
print('示例2 输出:',solve('199100199'))
print('别人错的 11#',solve('1023'))
没有更改,减少一下行数。def solve(s:'str of int')->bool:
def num(a,b):
while True:
yield a+b
a,b = b,a+b
le = len(s)
for l in range(1,(le//2)+1):
for r in range(1,le-l):
if r>1 and s[l] == '0':break
n, get, t = iter(num(int(s[:l]),int(s[l:l+r]))), s[:l+r], 2
while len(get)<=le:
if get == s and t>=3:return True
get += str(next(n))
t += 1
return False
if __name__ == '__main__':
print('示例1 输出:',solve('112358'))
print('示例2 输出:',solve('199100199'))
print('别人错的 11#',solve('1023'))
|