华为机试HJ87密码强度等级

华为机试HJ87密码强度等级

题目:

在这里插入图片描述
在这里插入图片描述

想法:

本题根据题目要求一步步写即可

input_str = input()

score = 0

if len(input_str) < 5:
    score += 5
elif len(input_str) >= 5 and len(input_str) <= 7:
    score += 10
else:
    score += 25

number = 0
up_char = 0
low_char = 0
other = 0

for i in input_str:
    if i.isdigit():
        number += 1
    elif i.isupper():
        up_char += 1
    elif i.islower():
        low_char += 1
    else:
        other += 1

if up_char == 0 or low_char == 0:
    score += 10
else:
    score += 20

if number == 1:
    score += 10
elif number > 1:
    score += 20

if other == 1:
    score += 10
elif other > 1:
    score += 25

if number > 0 and up_char > 0 and low_char > 0 and other > 0:
    score += 5
elif number > 0 and up_char + low_char > 0 and other > 0:
    score += 3
elif number > 0 and up_char + low_char > 0:
    score += 2

if score >= 0 and score < 25:
    print("VERY_WEAK")
elif score >= 25 and score < 50:
    print("WEAK")
elif score >= 50 and score < 60:
    print("AVERAGE")
elif score >= 60 and score < 70:
    print("STRONG")
elif score >= 70 and score < 80:
    print("VERY_STRONG")
elif score >= 80 and score < 90:
    print("SECURE")
elif score >= 90:
    print("VERY_SECURE")

时间复杂度: O ( n ) O(n) O(n)
空间复杂度: O ( 1 ) O(1) O(1)

# 整理上述写法
def score_tool(input_str):
    score = 0
    number = 0
    up_char = 0
    low_char = 0
    other = 0

    if len(input_str) < 5:
        score += 5
    elif len(input_str) >= 5 and len(input_str) <= 7:
        score += 10
    else:
        score += 25

    for i in input_str:
        if i.isdigit():
            number += 1
        elif i.isupper():
            up_char += 1
        elif i.islower():
            low_char += 1
        else:
            other += 1

    if up_char == 0 or low_char == 0:
        score += 10
    else:
        score += 20

    if number == 1:
        score += 10
    elif number > 1:
        score += 20

    if other == 1:
        score += 10
    elif other > 1:
        score += 25

    if number > 0 and up_char > 0 and low_char > 0 and other > 0:
        score += 5
    elif number > 0 and up_char + low_char > 0 and other > 0:
        score += 3
    elif number > 0 and up_char + low_char > 0:
        score += 2
    return score

def level(score):
    if score >= 0 and score < 25:
        return "VERY_WEAK"
    elif score >= 25 and score < 50:
        return "WEAK"
    elif score >= 50 and score < 60:
        return "AVERAGE"
    elif score >= 60 and score < 70:
        return "STRONG"
    elif score >= 70 and score < 80:
        return "VERY_STRONG"
    elif score >= 80 and score < 90:
        return "SECURE"
    elif score >= 90:
        return "VERY_SECURE"

input_str = input()

score = score_tool(input_str)
print(level(score))
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值