题解 | 密码验证合格程序
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
def check(string):
if len(string)<8:
return False
a,b,c,d=0,0,0,0
for s in string:
if s>='A' and s<='Z':
a=1
elif s>='a' and s<='z':
b=1
elif s>='0' and s<='9':
c=1
else:
d=1
if (a+b+c+d)<3:
return False
for i in range(len(string)-3):
if string.count(string[i:i+3])>=2:
return False
return True
while True:
try:
string=input()
if check(string):
print("OK")
else:
print("NG")
except:
break
判断相同字串数是否>=2,就用count(子串)就可以了,count的参数可以是某个字母,也可以是某个字符串。

