题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
# 检查长度大于2的重复子串
def check_repeat(s):
i = 0
while i + 3 <= len(s):
if s.count(s[i:i+3]) > 1:
return True # 有重复子串
i += 1
return False
while True:
try:
s = input()
# 长度不超过8,NG
if len(s) <= 8:
print('NG')
continue
# 大小写字母、数字、其他
dic = {
'upper' : False,
'lower' : False,
'digit' : False,
'other' : False
}
for c in s:
if c.isupper():
dic['upper'] = True
elif c.islower():
dic['lower'] = True
elif c.isdigit():
dic['digit'] = True
else:
dic['other'] = True
count = 0
for k in dic:
if dic[k]:
count += 1
if count < 3:
print('NG')
continue
# 检查是否存在长度大于2的重复子串
if check_repeat(s):
print('NG')
continue
print('OK')
except:
break