题目描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度大于2的子串重复
输入描述:
一组或多组长度超过2的字符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入
复制
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出
复制
OK
NG
NG
OK
- 有序列表内容
- 有序列表内容
while True:
try:s1=input() k=0 mod=0 is_a=0 is_A=0 is_0=0 is_q=0 # print("s1=",s1) flag=True for i in s1:
判断每个字符是否是大小写,数字,或者其他
# print(i) if i>= 'a' and 'z'>=i: mod=1 if is_a==0 : is_a=is_a+1 elif i>='A' and 'Z'>=i: mod=1 if is_A==0 : is_A=is_A+1 elif i in '0123456789' :
判断是否为数字,刚开始用int去判断,发现会对其他非数字字符用int会报异常错误
mod=1 if is_0==0: is_0=is_0+1 elif mod==0 and is_q==0: mod=1 is_q=is_q+1 mod=0
s1.count为某个字符串的次数,s1.count(s1[i:i+3])为3个字符连续取某3个字符串出现的次数
for i in range(len(s1)-3): if s1.count(s1[i:i+3])>1: flag=False if len(s1)>8 and (is_a+is_A+is_0+is_q)>=3 and flag==True:
判断flag==true,之前用flag()会自动出现异常错误
print("OK") else: print("NG")
except:break