题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

#include <iostream>
#include <cstring>

using namespace std;

int main() {
    string str1;
    int count = 0;
    cin >> str1;

    if (str1.size() <= 4) count = 5;
    else if (str1.size() <= 7) count = 10;
    else count = 25;

    int upper = 0, lower = 0, number = 0, symbol = 0;
    for (int i = 0; i < str1.size(); i++) {
        if (str1[i] >= 'A' && str1[i] <= 'Z') ++upper;
        else if (str1[i] >= 'a' && str1[i] <= 'z') ++lower;
        else if (str1[i] >= '0' && str1[i] <= '9') ++number;
        else ++symbol;
    }

    if (lower) count += 10;
    if (upper) count += 10;

    if (number == 1) count += 10;
    else if (number > 1) count += 20;

    if (symbol == 1) count += 10;
    else if (symbol > 1) count += 25;

    if (upper && lower && number && symbol) count += 5;
    else if ((upper || lower) && number && symbol) count += 3;
    else if ((upper || lower) && number) count += 2;

    if (count >= 90) cout << "VERY_SECURE";
    else if (count >= 80)
        cout << "SECURE";
    else if (count >= 70)
        cout << "VERY_STRONG";
    else if (count >= 60)
        cout << "STRONG";
    else if (count >= 50)
        cout << "AVERAGE";
    else if (count >= 25)
        cout << "WEAK";
    else if (count >= 0)
        cout << "VERY_WEAK";

    return 0;
}
全部评论

相关推荐

与火:这不接? 留子的钱不挣白不挣
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务