阅读原文:https://www.cnblogs.com/xiaotongtt/p/10796912.html
题目描述
密码要求:
1.长度超过8位
2.包括大小写字母、数字、其它符号,以上四种中的至少三种
3.不能有相同长度超2的子串重复
说明:长度超过2的子串
输入描述:
一组或多组长度超过2的子符串,每组占一行
输出描述:
如果符合要求输出 OK,否则输出 NG
示例1:
输入
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出
OK
NG
NG
OK
Python code:
def fun1(str):
if len(str) > 8:
return 1
else:
return 0
def fun2(str):
num1 = 0
num2 = 0
num3 = 0
num4 = 0
for i in str:
if 'a'<=i and i<='z':
num1 = 1
elif 'A' <=i and i<='Z':
num2 = 1
elif '0' <=i and i<='9':
num3 = 1
else:
num4 = 1
if (num1+num2+num3+num4) >=3:
return 1
else:
return 0
def fun3(str):
for i in range((len(str)-3)):
if str[i:i+3] in str[i+1:]:
return 0
break
return 1
while True:
try:
str1 = input()
if fun1(str1) and fun2(str1) and fun3(str1):
print('OK')
else:
print('NG')
except:
break
思路:将每个条件单独考虑,写成一个个函数。不定多少组输入时,用while循环。