题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
# 这是纯应用题目
# 判断数字,然后长度判断
def get_str(str_list):
num_list = ['0','1','2','3','4','5','6','7','8','9']
str_list.append('a')
path = []
result = []
for i in range(len(str_list)):
if str_list[i] in num_list:
path.append(str_list[i])
if str_list[i] not in num_list and str_list[i-1] in num_list:
result.append(path)
path = []
# print(result)
# 进行比较和输出
num = 0
for i in range(len(result)):
if len(result[i]) > num:
num = len(result[i])
res = result[i]
elif len(result[i]) == num:
res = res + result[i]
print("".join(res)+','+str(num))
while True:
try:
str_list = list(input())
get_str(str_list)
except:
break
