题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
事件复杂度:O(n), 空间复杂度:O(n)
对于没有switch-case语句的python而言,这代码总显得很僵硬。这时候牛客的Python版本是3.9.0,还不支持3.10的match-case
while True:
try:
password = input()
except:
break
score = 0
num_cou = 0
lowercase = 0
capital = 0
character = 0
if len(password) <= 4:
score = 5
elif 5 <= len(password) <= 7:
score = 10
else:
score = 25
for i in range(len(password)):
if '0' <= password[i] <= '9' and num_cou < 2:
num_cou += 1
elif 'a' <= password[i] <= 'z' and lowercase == 0:
lowercase = 1
elif 'A' <= password[i] <= 'Z' and capital == 0:
capital = 1
elif ('!' <= password[i] <= '/' or ':' <= password[i] <= '@' or '[' <= password[i] <= '`' or '{' <= password[i] <= '~') and character < 2:
character += 1
if lowercase + capital == 1:
score += 10
elif lowercase + capital == 2:
score += 20
if num_cou == 1:
score += 10
elif num_cou == 2:
score += 20
if character == 1:
score += 10
elif character == 2:
score += 25
if lowercase and capital and num_cou and character:
score += 5
elif (lowercase or capital) and num_cou and character:
score += 3
elif (lowercase or capital) and num_cou:
score += 2
if score >= 90:
print("VERY_SECURE")
elif score >= 80:
print("SECURE")
elif score >= 70:
print("VERY_STRONG")
elif score >= 60:
print("STRONG")
elif score >= 50:
print("AVERAGE")
elif score >= 25:
print("WEAK")
else:
print("VERY_WEAK")