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

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

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

import sys
s = list(sys.stdin.readline().strip())
list1 = []    
for char in s:
    if char.isupper() or char.islower():
        list1.append('.')
    else:
        list1.append(char)
list2 = (''.join(list1)).split('.')
max_word = ''
max_count = 0
for i in list2:
    if i != '':
        if len(i) > max_count:
            max_word = i
            max_count = len(i)
        elif len(i) == max_count:
            max_word += i
print(max_word,',',max_count,sep = '')


全部评论

相关推荐

明日Star:第一个项目修一修,点不用多3-4个,描述就是优化+指标量化。第二个项目换一下吧,换个agent
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务