题解 | #在字符串中找出连续最长的数字串#正则提取判断最大
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import re while True: try: dstr = input() number = re.findall("\d+",dstr) maxlen = 0 maxstr = "" for i in number: if len(i)>maxlen: maxstr = i maxlen = len(i) elif len(i)==maxlen: maxstr = maxstr+i print (maxstr+","+str(maxlen)) except: break # while True: # try: # dstr = input() # for i in dstr: # if not i.isdigit(): # dstr = dstr.replace(i," ") # maxnum = 1 # maxstr = "" # for i in dstr.split(" "): # if len(i)>maxnum: # maxnum = len(i) # maxstr = i # elif len(i)==maxnum: # maxstr = maxstr+i # if maxstr == "": # print (",0") # else: # print(maxstr+","+str(maxnum)) # except: # break # # def maxlen(dstr,i,maxnum): # # j = i+1 # # while j<maxnum: # # if dstr[i:j+1].isdigit(): # # j=j+1 # # else: # # return dstr[i:j],j # # return dstr[i:j],j # # while True: # # try: # # dstr = input() # # sdict = {} # # maxnum = len(dstr) # # i = 0 # # maxlen = 0 # # maxstr = "" # # while i <maxnum: # # if dstr[i].isdigit(): # # nstr,i = maxlen(dstr,i,maxnum) # # if len(nstr) >maxlen: # # maxlen = len(nstr) # # maxstr = nstr # # elif len(nstr) == maxlen: # # maxstr = maxstr+nstr # # else: # # i = i+1 # # print (maxstr+","+str(maxlen)) # # except: # # break