题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import sys
# for line in sys.stdin:
# a = line.split()
# print(int(a[0]) + int(a[1]))
s = input()
s = list(s)
# 长度判断合格与否
def lenisok(s):
if len(s) > 8:
return True
# 判断元素的种类大于三种
def classisok(s):
caps = 0
lows = 0
numbers = 0
others = 0
for x in s:
if x >= "A" and x <= "Z":
caps = 1
elif x >= "a" and x <= "z":
lows = 1
elif x >= "0" and x <= "9":
numbers = 1
else:
others = 1
sum = caps + lows + numbers + others
return sum
#验证字符串中有没有2个以上的重复的字符串,先将大于2个字符的字符串遍历出来,然后对遍历出来的元素组成的列表做一##个去重前后的对比
def f(s):
n=len(s)
L=[]
for length in range(3,n+1):
for index in range(0,n-length):
L.append(s[index:index+length])
#print(L)
m1 = len(L)
#print(set(L))
L2=[]
for x in L:
x="".join(x)
L2.append(x)
m2 =len(set(L2))
if m1>m2:
return False
else:
return True
if classisok(s) >= 3 and lenisok(s) and f(s):
print("OK")
else:
print("NG")
查看4道真题和解析