题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys passwords = [] for line in sys.stdin: pw = line.strip() passwords.append(pw) def no_repeat_substr(s): substrs = set() for l in range(3, len(s) + 1): for i in range(0, len(s) + 1 - l): substr = s[i:i+l] if substr in substrs: return False substrs.add(substr) return True def satisfy_reqs(s): reqs = [False, False, False, False] for c in s: if c.isupper(): reqs[0] = True elif c.islower(): reqs[1] = True elif c.isnumeric(): reqs[2] = True else: reqs[3] = True return (sum([1 for req in reqs if req]) >= 3) for pw in passwords: if len(pw) > 8 and satisfy_reqs(pw) and no_repeat_substr(pw): print("OK") else: print("NG")