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

密码验证合格程序

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

passwds = []

while 1:
    try:
        passwd = input()
        passwds.append(passwd)
    except:
        break

valid_passwd = [0 for _ in range(len(passwds))]
for i, n in enumerate(passwds):
    if len(n) <= 8:
        continue
    else:
        upper_num = 0
        lower_num = 0
        digit_num = 0
        special_num = 0
        repeat_seq = 0
        for j, char in enumerate(n):
            if char.isupper():
                if not upper_num:
                    upper_num = 1
            elif char.islower():
                if not lower_num:
                    lower_num = 1
            elif char.isdigit():
                if not digit_num:
                    digit_num = 1
            elif char == ' ' or char == '\n':
                pass
            else:
                if not special_num:
                    special_num = 1
            if j > 4 and n[j-2:j+1] in n[:j-2]:  # 判断重复字符串是否已经存在,只用判断最短情况即可
                repeat_seq = 1
        if repeat_seq:
            continue
        if not upper_num+lower_num+digit_num+special_num >= 3:
            continue
        valid_passwd[i] = 1
# print(upper_num, lower_num, digit_num, special_num)
for n in valid_passwd:
    if n:
        print('OK')
    else:
        print('NG')

https://blog.csdn.net/u012804784/article/details/131149259

利用内置函数或者正则化(re.match(r'[A-Z]', char))表达式判断大小写、数字

全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务