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

密码验证合格程序

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

import sys
import re

for x in sys.stdin:
    x = x.strip()
    
    if len(x) < 8:
        print('NG')
        continue

    y = 0 
    if re.search(r'[a-z]+', x) is not None:
        y += 1
    if re.search(r'[A-Z]+', x) is not None:
        y += 1
    if re.search(r'[0-9]+', x) is not None:
        y += 1
    if re.search(r'[^(0-9a-zA-Z)]+', x) is not None:
        y += 1
    if y < 3:
        # print(y)
        print('NG')
        continue
    
    # 滑动窗口判断有么有公共元素
    def catch_ii(x):
		# 大于2,那就是最小是3
        for win in range(3, len(x)-1):
            mp = {}
            for i in range(len(x)-win):
                item = x[i:i+win]
                if item in mp:
                    # print(item)
                    return True
                mp[item] = 1
        return False

    if catch_ii(x):
        print('NG')
    else:
        print('OK')






全部评论

相关推荐

09-24 17:30
门头沟学院 Java
叁六玖:上个班还要,七连面,唐三成神都只有九考呢,这公司怕不是要招个半神
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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