解题思路:我得思路都在代码注释中
参考代码:
m = int(input()) # 将输入的字符串存入列表 allstr = [] i = 0 while i < m: allstr.append(input()) i += 1 # 建立特殊字符数组 testr = "~!@#$%^" for s in allstr: lenth = len(s) if lenth < 8 or lenth > 16: print("NO") continue flag = 0 # 判断密码中是否含有大小写、数字、特殊字符 a = b = c = d = 0 for s1 in s: if s1 >= 'A' and s1 <= 'Z': a = 1 if s1 >= 'a' and s1 <= 'z': b = 1 if s1 >= '0' and s1 <= '9': c = 1 if s1 in testr: d = 1 # 只要密码中至少包含3种不同的字符种类,就结束当前字符串判断,继续判断下一个字符串 if a + b + c + d >= 3: flag = 1 print("YES") break if flag == 0: print("NO")
0.0分
0 人评分