题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
比较暴力
def strings(string): n = len(string) sums = 0 a = [] if n > 8: # 满足条件一 for i in string: if i.isnumeric(): sums += 1 break for i in string: if i.islower(): sums += 1 break for i in string: if i.isupper(): sums += 1 break for i in string: if not i.isnumeric() and not i.isalpha(): sums += 1 break if sums >= 3 : # 满足条件二 # 对字串进行暴力处理 for i in range(len(string)): for j in range(i+3,len(string)+1): # i+3 即长度大于2的字串 a.append(string.count(string[i:j])) # 统计 字串在原字符串中出现的次数 if max(a) > 1 : # 大于1即存在重复字串 return 'NG' else : return 'OK' else : return 'NG' else: return 'NG' while True : try: string = input().strip() print(strings(string)) except: break