题解 | #在字符串中找出连续最长的数字串#
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
冲冲冲,每天都要刷题啊!!!
while True: try: n=input() for i in n: if not i.isdigit(): n=n.replace(i,' ') n=n.split() n=sorted(n,key = lambda x :len(x) ,reverse=True) #按长度排序 maxlen=0 maxinde=[0] #栈,储存索引 res='' for x,i in enumerate(n): if len(i)>maxlen: #如果当前值比最大值大,替换最大值 maxlen=len(i) maxinde.pop() #推出最大值 maxinde.append(x) #压入当前值索引 elif len(i)==maxlen: #如果相等 maxinde.append(x) #压入索引 for j in maxinde: res+=n[j] print(res+','+str(maxlen)) except: break