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

密码验证合格程序

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

import sys, string

strw = string.punctuation
src_digits = string.digits              
src_uppercase = string.ascii_uppercase  
src_lowercase = string.ascii_lowercase

def func(w):    
    x = []
    for i in w:
        if i in src_digits and 1 not in x:
            x.append(1)
        elif i in src_lowercase and 2 not in x:
            x.append(2)
        elif i in src_uppercase and 3 not in x:
            x.append(3)
        elif i in strw and 4 not in x:
            x.append(4)
        elif len(x) > 2:
            return True
    if len(x) < 3:
        return False

def func1(w:str)->int:
    n = len(w)
    q = []
    for i in range(n):
        z = w[i:]
        for j in range(3,len(z)//2+1):
            if z[:j] in z[j:]:
                q.append(1)
    if len(q) != 0:
        return False
    else:
        return True
            
            
    
    
for i in sys.stdin.readlines():
    if len(i) <= 8:
        print('NG')
        continue
    elif not func(i):
        print('NG')
        continue
    elif not func1(i):
        print('NG')
        continue
    print('OK')
    

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
05-20 21:57
已编辑
门头沟学院 Java
喜欢吃卤蛋的悲伤蛙在...:建信融通没消息吧,我2说有实习挂简历不理了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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