题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

def test(password):
    if len(password) < 9:
        return False

    types = {"number", "lower", "upper", "others"}
    seen_substrings = password
    # Check for at least three types of characters
    type_count = set()
    for char in password:
        if "0" <= char <= "9":
            type_count.add("number")
        elif "a" <= char <= "z":
            type_count.add("lower")
        elif "A" <= char <= "Z":
            type_count.add("upper")
        else:
            type_count.add("others")

    if len(type_count) < 3:
        return False

    # Check for repeated substrings of length greater than 2
    for i in range(len(password)-2):
            substring = password[i : i + 3] 
            if seen_substrings.count(substring)>1:
                return False

    return True

while True:
    try:
        password = input()
        if test(password):
            print("OK")
        else:
            print("NG")
    except EOFError:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
06-25 16:25
梧州学院 Java
愿汐_:项目介绍那么长,然而你做了啥就一句话?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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