题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import re
import sys
def checkPassword(res):
if len(res) <= 8:
return "NG"
for i in range(len(res) - 2):
if res.count(res[i:i+3]) > 1:
return "NG"
pattern_digit = ".*[0-9]+.*"
pattern_latter1 = ".*[a-z]+.*"
pattern_latter2 = ".*[A-Z]+.*"
pattern_others = ".*([^a-zA-Z0-9])+.*"
count = 0
if re.match(pattern_digit,res):
# print(1)
count += 1
if re.match(pattern_latter1,res):
# print(2)
count += 1
if re.match(pattern_latter2,res):
# print(3)
count += 1
if re.match(pattern_others,res):
# print(4)
count += 1
if count > 2:
return "OK"
else:
return "NG"
input_line = input()
while input_line:
try:
print(checkPassword(input_line))
input_line = input()
except:
break