题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
http://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import sys
list01 = [line.replace("\n", "") for line in sys.stdin] # 获取所有输入值
for i in list01:
stri = ""
for j in i:
if j.isdecimal(): # 将所有连续数字提取
stri += j
else:
stri += " "
list02 = stri.split() # 形成所有连续数字的列表
stri01 = ""
stri02 = ""
for n in list02:
if len(n) > len(stri01):
stri01 = n # 获取长度最长的连续数字字符串
stri02 += stri01
for m in list02:
if len(m) == len(stri01) and m != stri01: # 获取其他长度相同的连续数字字符串
stri02 += m
else:
continue
print(f"{stri02},{len(stri01)}")