题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
用python集合挺方便的
def get_ans(s):
return 'OK' if (len(s)>8 and three_types(s) and sub_str(s)) else 'NG'
def three_types(s):
mark=set()
for i in s:
if i.islower(): mark.add('lower')
elif i.isupper(): mark.add('upper')
elif i.isnumeric(): mark.add('numeric')
elif i!=' ' or i!='\n': mark.add('else')
return len(mark)>=3
def sub_str(s):
mark=set()
for i in range(len(s)-3):
if s[i:i+3] not in mark:
mark.add(s[i:i+3])
else: return False
return True
if __name__=='__main__':
import sys
lines = []
while True:
line = sys.stdin.readline().strip()
if line == "":
break
lines.append(line)
for item in lines:
print(get_ans(item))
题解-数据结构与算法 文章被收录于专栏
小菜鸟的题解