简答题
偏难
#19525
密码合规检测 【问题描述】 1. 网站注册需要有用户名和密码,编写程序以检查用户输入密码的有效性。 2. 合法的密码只能由 a-z 之间 26 个小写字母、A-…
密码合规检测
【问题描述】
1. 网站注册需要有用户名和密码,编写程序以检查用户输入密码的有效性。
2. 合法的密码只能由 a-z 之间 26 个小写字母、A-Z 之间 26 个大写字母、0-9 之间 10个数字以及!@#$四个特殊字母构成。
3. 密码最短长度:6 个字符,密码最大长度:12 个字符。
4. 大写字母、小写字母和数字必须有其中两种,以及至少有四个特殊字符中的一个。
【输入描述】
1. 输入以英文逗号分隔的多个字符组合作为被检测密码。输入时的逗号都作为分隔符,不被视作检验密码本身。
2. 特别提示:常规程序中,输入时好习惯是有提示。考试时由于系统限定,输入时所有 input()函数不可有提示信息。
【输出描述】
1. 逐行输出 0 个或多个合规的密码。
2. 输出顺序以输入字符串出现先后为序,即先出现则先输出。
【样例输入 1】
【样例输出 1】
答案与解析
正确答案:<pre class="brush:python;toolbar:false">#密码合规检测
pwdList = input().split(",")
for itm in pwdList:
lowerCount = 0
upperCount = 0
digitCount = 0
specialCount = 0
otherCount = 0
for letter in itm:
if ord('a') <= ord(letter) <= ord('z'):
lowerCount += 1
elif ord('A') <= ord(letter) <= ord('Z'):
upperCount += 1
elif ord('0') <= ord(letter) <= ord('9'):
digitCount += 1
elif letter in "!@#$":
specialCount += 1
else:
otherCount += 1
break
triState = 0 #大写小写数字种类数量
if lowerCount > 0:
triState += 1
if upperCount > 0:
triState += 1
if digitCount > 0:
triState += 1
if triState >= 2 and specialCount >0 and (6 <= len(itm) <= 12) and otherCount == 0:
print(itm)</pre><p><br/></p>
这道题暂未补解析。