当前位置:   article > 正文

HJ87密码等级

HJ87密码等级

这个题目就是细心处理一下就行,比较简单

#include <ctype.h>
#include <stdio.h>
#include <stdbool.h>

void PrintLevel(unsigned int score)
{
    if(score >= 90)
    {
        printf("VERY_SECURE");
    }
    else if(score >= 80)
    {
        printf("SECURE");
    }
    else if(score >= 70)
    {
        printf("VERY_STRONG");
    }
    else if(score >= 60)
    {
        printf("STRONG");
    }
    else if(score >= 50)
    {
        printf("AVERAGE");
    }
    else if(score >= 25)
    {
        printf("WEAK");
    }else if(score >= 0)
    {
        printf("VERY_WEAK");
    }
}

int GetScoreByStrlen(int *score, unsigned int len)
{
    if(len <= 4)
    {
        *score = 5;
    }else if(len <= 7)
    {
        *score = 10;
    }
    else {
        *score = 25;
    }
    return 0;
}

int GetScoreByCharacter(int *score, char* array, int len)
{
    bool withAlphaFlag = false;
    bool alphaWithLowerFlag = false;
    bool alphaWithUpperFlag = false;

    bool withDigitFlag = false;
    int digitCount = 0;

    bool withCharacterFlag = false;
    int characterCount = 0;

    for(int i = 0; i < len; i++)
    {
        if(isalpha(array[i]))
        {
            withAlphaFlag = true;
            if(array[i] >= 'a' && array[i] <= 'z')
            {
                alphaWithLowerFlag = true;
            }
            if(array[i] >= 'A' && array[i] <= 'Z')
            {
                alphaWithUpperFlag = true;
            }
        }
        else if(isdigit(array[i]))
        {
            withDigitFlag = true;
            digitCount++;
        }
        else {
            withCharacterFlag = true;
            characterCount++;
        }
    }

    int alphaScore = 0;
    if(!withAlphaFlag)
    {
        alphaScore = 0;
    }else {
        if(alphaWithLowerFlag && alphaWithUpperFlag)
        {
            alphaScore = 20;
        }
        else {
            alphaScore = 10;
        }
    }
    *score += alphaScore;

    int digitScore = 0;
    if(!withDigitFlag)
    {
        digitScore = 0;
    }else {
        if(digitCount == 1)
        {
            digitScore = 10;
        }
        else {
            digitScore = 20;
        }
    }
    *score += digitScore;

    int characterScore = 0;
    if(!withCharacterFlag)
    {
        characterScore = 0;
    }else {
        if(characterCount == 1)
        {
            characterScore = 10;
        }
        else {
            characterScore = 25;
        }
    }
    *score += characterScore;

    int specialScore = 0;
    if(alphaWithLowerFlag && alphaWithUpperFlag && withDigitFlag && withCharacterFlag)
    {
        specialScore = 5;
    }
    else if(withAlphaFlag && withDigitFlag && withCharacterFlag)
    {
        specialScore = 3;
    }
    else if(withAlphaFlag && withDigitFlag)
    {
        specialScore = 2;
    }
    *score += specialScore;

    return 0;
}

int main() {
    char strArray[301] = {'\0'};
    while (scanf("%s",strArray) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        int score = 0;
        
        int len = strlen(strArray);
        GetScoreByStrlen(&score, len);
        GetScoreByCharacter(&score, strArray, len);
        PrintLevel(score);
    }
    return 0;
}
  • 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
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号