题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
python3解法简单明了
def func(s):
a = b = c = d = 0
#建立三种情况的列表
lst1 = [chr(i) for i in range(ord('A'), ord('Z') + 1)] #大写
lst2 = [chr(i) for i in range(ord('a'), ord('z') + 1)] #小写
lst3 = [str(i) for i in range(10)]#数字(需转换成字符串)
if len(s) <= 8:
return 'NG'
for i in s:
if i in lst1:
a = 1
elif i in lst2:
b = 1
elif i in lst3:
c = 1
else:
d = 1
if (a + b + c + d) < 3:
return 'NG'
for i in range(len(s) - 2):
x = s[i:i + 3]
if x in s[i + 3:]:
return 'NG'
return 'OK'
while True:
try:
s = input()
print(func(s))
except:
break