1 题目描述
Alice将要设置自己在某个网站上的用户密码,她希望自己所设置的密码中只包含数字和字母,且具有一定的强度。她写下了几个待选密码,并将它们交给Bob,让Bob帮自己判断其中哪些密码是具有一定的强度的。Bob认为如果密码符合以下条件,则是具有一定强度的:
密码的长度至少为6;
密码包含的数字字符个数少于字母字符个数;
密码中没有连续5个字符均是字母;
密码中没有连续两个字符是一模一样的。
现在Bob希望你帮他写一个程序,选出那些Bob认为具有一定强度的密码。
输入描述 第一行是一个正整数n,表示Alice写下的密码个数。
接下来n行每行一个字符串,保证只包含数字和字母,每一行都代表Alice写下的一个密码。
输出描述 输出n行,每行是一个字符串”YES”或”NO”,其中第i行为”YES”表示输入的第i个密码是具有一定强度的,”NO”则表示不具有一定强度。
样例输入
4 A2b3c5d2ffc23 c3c3c3c3 c3c3c3c3c aAaAaA
样例输出
NO NO YES NO
2 Python 实现import re
n = int(input())
sentence = []
while 1:
s = input()
if s != "":
sentence.append(s)
else:
break
def is_num_leq_letter(pwd):
# 判断数字字符个数少于字母字符个数
num = len(re.findall(r"\d",pwd))
w = len(re.findall(r"[a-zA-Z]",pwd))
if num0:
return True
else:
return False
def isContinuousChar(pwd):
# 判断是否存在有连续两个相同的字母
#[a-zA-Z]是为了匹配单个字母
# \1是为了匹配与第一组内容重复的字母
num = len(re.findall(r"([a-zA-Z]|[0-9])\1",pwd))
if num>0:
return True
else:
return False
for s in sentence:
if len(s)>=6 and is_num_leq_letter(s) and not five_continue(s) and not isContinuousChar(s):
print('YES')
else:
print('NO')
print()