题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys
def check_len(password):
for i in range(0, len(password) -3):
x = password[i: i + 3]
if len(password.split(x)) > 2: # 长度大于2的包含公共元素的子串重复
print("NG")
return False
return True
while True:
check_list = [0] * 4
try:
password = input()
if len(password) < 8: # 长度超过8位
print("NG")
continue
for i in password:
if 'a' <= i <= 'z': # 小写
check_list[0] = 1
elif 'A' <= i <= 'Z': # 大写
check_list[1] = 1
elif '0' <= i <= '9': # 数字
check_list[2] = 1
else:
check_list[3] = 1 # 其他字符
if sum(check_list) < 3: # 至少三种
print("NG")
continue
if not check_len(password):
continue
print("OK")
except:
break

查看14道真题和解析