当前位置:   article > 正文

华为机试HJ87密码强度等级

华为机试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")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

时间复杂度: 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))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/914588
推荐阅读
相关标签
  

闽ICP备14008679号