题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
while 1: try: s=input() # 长度是否超过8 if len(s)>8: # 是否不含空格或换行 if s.count(' ')==0 and s.count('\n')==0: # 是否包含至少3种字符 s1='' for i in s: if i.isdigit(): s1 += 'd' elif i.isupper(): s1 += 'u' elif i.islower(): s1 += 'l' else: s1 += 'o' #print(s1,set(s1)) if len(set(s1))>=3: # 是否能分割出两个相等的长度大于 2 的子串 a={} for i in range(len(s)): for j in range(i+2,len(s)): b=[] for k in range(j+1,len(s)-(j-i)): #此处可以简化,只看长度为3的子串即可 b.append(s[k:k+j-i+1]) if s[i:j+1] in a.keys(): continue a[s[i:j+1]]=b #print(a) for key in a.keys(): if key in a[key]: print('NG') break else: print('OK') else: print('NG') else: print('NG') else: print('NG') except: break ''' a='fsd\njfn' b='vdv fsdf' print(a,b) print(a.count('\n'),b.count(' ')) ~!+8+*fQO%&(2974)W9~D6X60T5%@1V1961*&+8+!046F#q#+S * Ab* ABASasd*$ ABASasd0123 sadsad1231*$ * ADDAS012$%@ aAAAAAAds3456!@# * ''' ''' pw='1111sc#h' #此密码应该是ok #下列方法错误: dc = {} for i in range(len(pw) - 2): # 遍历所有的子字符串起点 if pw[i:i+3] in dc: # 在字典中搜索 print('False') break else: dc[pw[i:i+3]]=1 # 如果未曾经出现过则加入字典中,等待之后的判定 else: # 不能直接print('True'),需有else: print('True') #print(dc) #print('True') # 下列方法正确: for i in range(len(pw) - 2): if pw[i:i+3] in pw[i+3:]: print('False') break else: print('True') '''