题解 | 密码验证合格程序
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys
import re
for line in sys.stdin:
pw = line.strip()
if len(pw) < 8:
print('NG')
continue
a, b, c = re.search(r'[A-Z]', pw), re.search(r'[a-z]', pw), re.search(r'[0-9]', pw)
re_pw = ''.join([chr(x) for x in range(33, 127)])
re_pw = re_pw[:15] + re_pw[25:32] + re_pw[58:64] + re_pw[90:]
d = re.search(rf'[{re_pw}]', pw)
if not (a and b and c or a and b and d or a and c and d or b and c and d):
print('NG')
continue
x = False
for i in range(len(pw) - 6):
if pw.count(pw[i:i+3]) > 1:
x = True
break
if x:
print('NG')
continue
print('OK')
查看7道真题和解析
