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

密码验证合格程序

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

import sys


def check_len(password):
    for i in range(0, len(password) -3):
            x = password[i: i + 3]
            if len(password.split(x)) > 2: # 长度大于2的包含公共元素的子串重复
                print("NG")
                return False
    return True

while True:
    check_list = [0] * 4
    try:
        password = input()
        if len(password) < 8: # 长度超过8位
            print("NG")
            continue
        for i in password:
            if  'a' <= i <= 'z': # 小写
                check_list[0] = 1
            elif 'A' <= i <= 'Z': # 大写
                check_list[1] = 1
            elif '0' <= i <= '9': # 数字
                check_list[2] = 1
            else:
                check_list[3] = 1 # 其他字符
        if sum(check_list) < 3: # 至少三种
            print("NG")
            continue
        if not check_len(password):
            continue
        print("OK")          
    except:
        break

全部评论

相关推荐

不愿透露姓名的神秘牛友
04-22 13:08
Data_Seven:真不知道这些企业哪来的成就感
点赞 评论 收藏
分享
许愿一个offer_...:不是啊,这个只代表你的面试官提交了你的面评,面试是否通过还是要看官网状态呢
腾讯2025实习生招聘
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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