题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
while True:
try:
s = input()
i = 0
ls = []
maxlen = 0
while i < len(s):
if s[i].isdigit():
for j in range(i, len(s)):
if not s[j].isdigit():
ls.append(s[i:j])
maxlen = max(maxlen, j - i)
i = j + 1
break
elif j == len(s) - 1:
ls.append(s[i : j + 1])
maxlen = max(maxlen, j - i + 1)
i = j + 1
break
else:
i += 1
for x in ls:
if len(x) == maxlen:
print(x, end="")
print(",%d" % maxlen)
except:
break
智元机器人成长空间 174人发布