给定一个字符串,返回最长的元音字母(aeiou)子串的长度

题目描述:
    给定一个字符串,返回最长的元音字母(aeiou)子串的长度.
    测试用例1:
    输入为:asdbuiodea  
    输出为:3   因为uio三个元音字母最长

def find(s):
    maxLength = 0    #连续的历史最大长度
    count = 0        #连续的长度
    endPoint = 0     #最后的位置记录
    for i in range(len(s)):
        if s[i] in "aeiou":
            count += 1
            if (maxLength < count):
                maxLength = count
                endPoint = i
        else :
            count = 0
    
    print(s[endPoint - maxLength + 1: endPoint + 1])   #输出:uio

if __name__ == "__main__":
    s = str(input())    #输入:sadbuiodea
    find(s)

 

Guess you like

Origin blog.csdn.net/cocos2dGirl/article/details/115799824