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

python 查找字符串中最长的数字子串 PTA,第1张

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)

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/788834.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-05
下一篇2022-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存