0
点赞
收藏
分享

微信扫一扫

python 查找字符串中最长的数字子串 PTA

刘员外__ 2022-04-29 阅读 119
python

在这里插入图片描述

import re
def find(s):
    max = 0
    count = 0
    end = 0
    if bool(re.search(r'\d', s))==False:
        print('No')
    else:
        for i in range(len(s)):
            if (s[i] >= '0' and s[i] <= '9'):
                count += 1
                if (max < count):
                    max = count
                    end = i
            else:
                count = 0
        print(s[end - max + 1:end + 1])

s = str(input())
find(s)
举报

相关推荐

0 条评论