题解 | #密码强度等级#

密码强度等级

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

#include <cctype>
#include <iostream>
using namespace std;

int main() {
    string msg;
    int num_count = 0;
    int symbol_conut = 0;
    int low_grapheme = 0;
    int sup_grapheme = 0;
    int score = 0;
    cin >> msg;
    if (msg.size() >= 8) {
        score += 25;
    } else if (msg.size() < 4) {
        score += 5;
    } else {

        score += 10;
        
    }
    for (char i : msg) {

        if (isdigit(i)) {
            num_count++;
        } else if (islower(i)) {
            low_grapheme = 1;
        } else if (isupper(i)) {
            sup_grapheme = 1;
        } else {
            symbol_conut++;
        }

    }
    //大小写
    if ((low_grapheme) & (!sup_grapheme) || (!low_grapheme) & sup_grapheme) {
        score += 10;
    } else if (low_grapheme && sup_grapheme) {
        score += 20;
    }
    //数字
    if (num_count == 1) {
        score += 10;
    } else if (num_count > 1) {
        score += 20;
    }
    //符号
    if (symbol_conut == 1) {
        score += 10;
    } else if (symbol_conut > 1) {
        score += 25;
    }
    //奖励
    if (symbol_conut > 0 && num_count > 0 && low_grapheme > 0 && sup_grapheme > 0) {
        score += 5;
    } else if ((symbol_conut > 0) && (num_count > 0) && ((low_grapheme > 0) ||
               (sup_grapheme > 0))) {
        score += 3;
    } else if ((low_grapheme > 0 || sup_grapheme > 0) && num_count > 0) {
        score += 2;
    }
    if (score >= 90) {
        cout << "VERY_SECURE" << endl;
    } else if (score >= 80) {
        cout << "SECURE" << endl;
    } else if (score >= 70) {
        cout << "VERY_STRONG" << endl;
    } else if (score >= 60) {
        cout << "STRONG" << endl;
    } else if (score >= 50) {
        cout << "AVERAGE" << endl;
    } else if (score >= 25) {
        cout << "WEAK" << endl;
    } else if(score<25){
        cout << "VERY_WEAK" << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

07-21 12:41
已编辑
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-24 12:26
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务