题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys def check_password(password): if len(password) <= 8: return "NG" bool_s = [False]*4 for char in password: if char.isdigit(): bool_s[0] = True elif char.islower(): bool_s[1] = True elif char.isupper(): bool_s[2] = True else: bool_s[3] = True if sum(bool_s) < 3: return "NG" for i in range(len(password) - 2): char = password[i:i+3] if password.find(char,i+1) != -1: return "NG" return "OK" input_data = sys.stdin.read().strip().splitlines() results = [check_password(password) for password in input_data] for result in results: print(result)