注意坑:长度是大于8,这边不使用re取匹配乱七八糟的数据了,直接使用string模块处理对应的字符字符是否存在,
import sys
import string
for x in sys.stdin:
password = x.strip()
# 判定长度
if len(password) <= 8:
print('NG')
continue
# 判定类型
upper,lower,symbol,number = 0, 0, 0, 0
for word in password:
if word in string.ascii_uppercase:
upper = 1
elif word in string.ascii_lowercase:
lower = 1
elif word in string.digits:
number = 1
elif word in string.punctuation:
symbol = 1
if upper + lower + symbol + number < 3:
print('NG')
continue
# 判定子串重复率
sub_list = []
for i in range(len(password)-2):
sub_list.append(password[i:i+3])
if len(sub_list) > len(set(sub_list)):
print('NG')
continue
# 前面的不符合就NG并跳出,符合就最终OK
print('OK')