题解 | 密码验证合格程序

密码验证合格程序

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

import sys

for line in sys.stdin:
    a = line.split()
    # print(a)
    password = a[0]
    if len(password) < 8:
        print("NG")
        continue
    c_class = set()

    for i,s in enumerate(password): # isupper, islower, isdigit 是方法(methods)而不是属性(properties),所以需要加上括号 () 来调用它们
        if s.isupper():
            c_class.add("upper")
        elif s.islower():
            c_class.add("lower")
        elif s.isdigit():
            c_class.add("digit")
        else:
            c_class.add("teshu")
        
    if len(c_class) < 3:
        print("NG")
        continue
        
    has_substr = False
    set1 = set()
    for i in range(len(password)-3):
        if password[i:i+3] not in set1:
            set1.add(password[i:i+3])
        else:
            has_substr = True
            print("NG")
            break
    if not has_substr:
        print("OK")
        

    
    
    


更新子串判断算法

全部评论

相关推荐

09-12 11:55
已编辑
湖南工商大学 Java
那一天的Java_J...:这种一堆问题的,别去
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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