题解 | 密码验证合格程序
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys
# 判断独立子串函数
def jugre(s,l):
enl = l//2
for wide in range(3,enl+1):
for idx in range(0,l//2+1):
if s.count(s[idx:idx+wide])!=1:
return 0
return 1
for line in sys.stdin:
s = line.strip()
l = len(s)
# 判断长度
if l < 8:
print('NG')
continue
su = [0]*4
for c in s:
if c.isdigit():
su[0]=1
elif c.islower():
su[1]=1
elif c.isupper():
su[2]=1
else:
su[3]=1
#判断字符
if sum(su)<3:
print('NG')
continue
#判断子串
if not jugre(s,l):
print('NG')
continue
print('OK')
查看27道真题和解析

小天才公司福利 1866人发布