密码验证合格程序(Python)

题目描述

密码要求:

1.长度超过8位 

2.包括大小写字母.数字.其它符号,以上四种至少三种

3.不能有相同长度超2的子串重复

说明:长度超过2的子串

输入描述:

一组或多组长度超过2的子符串。每组占一行

输出描述:

如果符合要求输出:OK,否则输出NG

示例1

输入

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出

OK
NG
NG
OK

来源:https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841?tpId=37&tqId=21243&rp=0&ru=/ta/huawei&qru=/ta/huawei/question-ranking


 

Python代码

import re
while True:    
    try:             
        s = input()              
        a = re.findall(r'(.{3,}).*1', s)  # 出现超过2次的字串        
        b1 = re.findall(r'd', s)  # 数字        
        b2 = re.findall(r'[A-Z]', s)  # 大写字母        
        b3 = re.findall(r'[a-z]', s)  # 小写字母        
        b4 = re.findall(r'[^0-9A-Za-z]', s)  # 非大小写字母和数字         
        print('OK' if ([b1, b2, b3, b4].count([]) <= 1 and a == [] and len(s) > 8) else 'NG')
    except:    
        break

来源:https://www.nowcoder.com/questionTerminal/184edec193864f0985ad2684fbc86841?f=discussion

原文地址:https://www.cnblogs.com/cassielcode/p/12613214.html