题解 | #在字符串中找出连续最长的数字串#

在字符串中找出连续最长的数字串

https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec

最扯蛋的python3

def func(s):
    t = 0
    res = []
    dic = {}
    lst = [str(i) for i in range(10)]
    i = 0
    while i < len(s):
        if s[i] in lst:
            tmp = s[i]
            for j  in range(i+1,len(s)+1):
                if s[j] in lst:
                    tmp += s[j]
                else:
                    i = j
                    break
            dic[str(tmp)] = len(tmp)
        else:
            i +=1
    for i in dic.values():
        if i >= t:
            t = i
    for i in dic.keys():
        if dic[i] == t:
            print(i,end = '')
    print(f',{t}')

while True:
    try:
        s= input()
        s = s+'e'
        func(s)
    except:
        break

全部评论

相关推荐

头像
10-09 19:35
门头沟学院 Java
洛必不可达:java的竞争激烈程度是其他任何岗位的10到20倍
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务