题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import re while True: try: s = input() if len(s) <= 8: # 1. 判断字符串长度 print("NG") else: # 2. 判断是否包括三种字符类型 A_Z = False a_z = False num = False other = False for i in s: if re.match("[A-Z]", i): A_Z = True elif re.match("[a-z]", i): a_z = True elif re.match("[0-9]", i): num = True else: other = True if A_Z + a_z + num + other < 3: print("NG") else: # 3. 判断子串重复 repeat = False for i in range(len(s)-5): for j in range(i+3,len(s)-2): if s[i] == s[j] and s[i+1]==s[j+1] and s[i+2]==s[j+2]: repeat = True break if repeat: print("NG") else: print("OK") except: break