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

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

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


# 这是纯应用题目
# 判断数字,然后长度判断

def get_str(str_list):
    num_list = ['0','1','2','3','4','5','6','7','8','9']
    str_list.append('a')
    path = []
    result = []
    for i in range(len(str_list)):
        if str_list[i] in num_list:
            path.append(str_list[i])
        if str_list[i] not in num_list and str_list[i-1] in num_list:
            result.append(path)
            path = []
    # print(result)
    # 进行比较和输出
    num = 0
    for i in range(len(result)):
        if len(result[i]) > num:
            num = len(result[i])
            res = result[i]

        elif len(result[i]) == num:
            res = res + result[i]

    print("".join(res)+','+str(num))


while True:
    try:
        str_list = list(input())
        get_str(str_list)

    except:
        break






全部评论

相关推荐

这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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