华为机试题-密码验证python实现

题目:

密码要求:

1.长度超过8位

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

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

说明:长度超过2的子串

输入描述:

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

输出描述:

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

代码:

import sys
import re
def CheckLen(code):
    if len(code)<8:
        return False
    return True
def CheckCha(code):
    f1=0
    f2=0
    f3=0
    f4=0
    for i in code:
        if i.islower():
            f1=1
        elif i.isupper():
            f2=1
        elif i.isdigit():
            f3=1
        else:
            f4=1
    if (f1+f2+f3+f4)>=3:
        return True
    return False
def CheckDul(code):
    for i in range(len(code)-3):
        if code.count(code[i:i+3])>1:
            return False
    return True
    
while(True):
    code = sys.stdin.readline().strip()
    if code=='':
        break
    if CheckDul(code) and CheckCha(code) and CheckLen(code):
        print("OK")
    else:
        #print(CheckCha(code))
        print("NG")


            
            
        
    
    

猜你喜欢

转载自www.cnblogs.com/Alwaysblue/p/12178364.html