密码验证合格(python版)

题目描述

密码要求:

1.长度超过8位

2.包括大小写字母.数字.其它符号,以上四种至少三种

3.不能有相同长度超2的子串重复

说明:长度超过2的子串

 

输入描述:

一组或多组长度超过2的子符串。每组占一行

输出描述:

如果符合要求输出:OK,否则输出NG

示例1

输入

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出

OK
NG
NG
OK

 

解法一

import re
try:
    while 1:
         
        s = raw_input()
         
        a = re.findall(r'(.{3,}).*\1', s)
        b1 = re.findall(r'\d', s)
        b2 = re.findall(r'[A-Z]', s)
        b3 = re.findall(r'[a-z]', s)
        b4 = re.findall(r'[^0-9A-Za-z]', s)
        print 'OK' if ([b1, b2, b3, b4].count([]) <= 1 and a == [] and len(s) > 8) else 'NG'      
except:
    pass

解法二:

import sys
import re
 
for line in sys.stdin:
     
    line = line.strip()
    #1
    if len(line) <= 8:
        print("NG")
        continue
    #2
    count = 0
    if re.search('[0-9]',line): count += 1
    if re.search('[a-z]',line): count += 1
    if re.search('[A-Z]',line): count += 1
    if re.search('[^a-zA-Z0-9]',line): count += 1
    if count < 3: 
        print("NG")
        continue
    #3:
    if re.search(r'.*(...)(.*\1)', line):
        print("NG")
        continue
     
    print("OK")

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值