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

密码验证合格程序

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

import sys

def is_safe(x):
    if len(x)<8:
        return 'NG'

    c = [0]*4
    for i in x:
        if ord(i) >= ord('0') and ord(i) <= ord('9'):
            c[0] += 1
        elif ord(i) >= ord('a') and ord(i) <= ord('z'):
            c[1] += 1
        if ord(i) >= ord('A') and ord(i) <= ord('Z'):
            c[2] += 1
        else:
            c[3] += 1
    
    stc = []
    for i in range(len(x)-3):
        stc.append(x[i:i+3])
    l1 = len(stc)
    l2 = len(set(stc))
    if  l1 != l2 :
        return 'NG'


    if c.count(0) > 1:
        return 'NG'
    else:
        return 'OK'

while 1:
    try:
        x = input()
        print(is_safe(x))
    except:
        break


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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