题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
while 1: try: s = input() s0 = [[], []] counter = 0 mark = 0 for i in range(len(s)): if i + 1 != len(s) and s[i].isdigit() and s[i + 1].isdigit(): if i + 2 != len(s): counter += 1 continue elif i + 2 == len(s) and s[i + 1].isdigit(): counter += 2 s0[0].append(s[i + 2 - counter : ]) s0[1].append(counter) counter = 0 break elif counter >= 1 and s[i].isdigit() and i + 1 != len(s) and not s[i + 1].isdigit(): counter += 1 s0[0].append(s[i - counter + 1 : i + 1]) s0[1].append(counter) counter = 0 elif counter == 0 and s[i].isdigit(): counter += 1 s0[0].append(s[i - counter + 1 : i + 1]) s0[1].append(counter) counter = 0 mark = max(s0[1]) for i in range(len(s0[0])): if len(s0[0][i]) == mark: print(s0[0][i], end='') else: continue print(',', end='') print(mark) except: break