题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
def test(password):
if len(password) < 9:
return False
types = {"number", "lower", "upper", "others"}
seen_substrings = password
# Check for at least three types of characters
type_count = set()
for char in password:
if "0" <= char <= "9":
type_count.add("number")
elif "a" <= char <= "z":
type_count.add("lower")
elif "A" <= char <= "Z":
type_count.add("upper")
else:
type_count.add("others")
if len(type_count) < 3:
return False
# Check for repeated substrings of length greater than 2
for i in range(len(password)-2):
substring = password[i : i + 3]
if seen_substrings.count(substring)>1:
return False
return True
while True:
try:
password = input()
if test(password):
print("OK")
else:
print("NG")
except EOFError:
break
查看8道真题和解析