题目描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度大于2的子串重复
输入描述:
一组或多组长度超过2的字符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出
OK
NG
NG
OK
实现
import sys
def type_pwd(pwd):
type_ = set()
for i in pwd:
if i.isalpha():
if i.upper() == i:
type_.add('upper')
else:
type_.add('lower')
elif i.isdigit():
type_.add('int')
else:
type_.add('other')
return len(type_)
def check_substring(pwd):
for i in range(len(pwd)-3):
count = pwd.count(pwd[i:i+3])
if count > 1:
return 1
def check(pwd):
if len(pwd) <= 8:
return 'NG'
if type_pwd(pwd) < 3:
return 'NG'
if check_substring(pwd) == 1:
return 'NG'
return 'OK'
while 1:
line = sys.stdin.readline().strip()
if line == '':
break
print(check(line))