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

密码验证合格程序

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

import sys

res = []

for line in sys.stdin:
    passwd = line.strip()
    has_repeat = False

    if len(passwd) < 8:
        res.append('NG')
        continue

    con = [0] * 4

    # 先判断是否有重复的字串
    for i in range(3, len(passwd) // 2 + 1):
        if has_repeat:
            break
        for j in range(len(passwd)):
            sub = passwd[j:j+i]
            if sub in passwd[j+i:]:
                has_repeat = True
                res.append('NG')
                break

    if has_repeat:
        continue

    for i in passwd:
        if i.isnumeric():
            con[0] = 1
        elif i.isupper():
            con[1] = 1
        elif i.islower():
            con[2] = 1
        else:
            con[3] = 1

    if con.count(1) >= 3:
        res.append('OK')
    else:
        res.append('NG')

for i in res:
    print(i)

全部评论

相关推荐

02-28 01:18
已编辑
南昌大学 后端工程师
后测速成辅导一两个月...:把开源经历放个人项目上边应该更好,就像大部分人都把实习经历放个人项目上边
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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