题解 | #密码强度等级#

密码强度等级

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")
全部评论

相关推荐

不愿透露姓名的神秘牛友
10-12 10:48
已编辑
秋招之苟:邻居家老哥19届双2硕大厂开发offer拿遍了,前几天向他请教秋招,他给我看他当年的简历,0实习实验室项目技术栈跟开发基本不沾边😂,我跟他说这个放在现在中厂简历都过不了
点赞 评论 收藏
分享
11-27 17:08
已编辑
牛客_产品运营部_私域运营
腾讯 普通offer 24k~26k * 15,年包在36w~39w左右。
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务