题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
http://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
两层循环
while True:
try:
s = input()
l = len(s)
max_ = 0
dic = {}
for i, c in enumerate(s):
if '0' <= c <= '9':
k = i
sub = ''
while k < l and '0' <= s[k] <= '9':
sub += s[k]
k += 1
n = len(sub)
if n > max_:
max_ = n
if n in dic:
dic[n].append(sub)
else:
dic[n] = [sub]
print(''.join(dic[max_])+','+str(max_))
except:
break