题解 | #密码强度等级#

密码强度等级

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    int score=0;
    if(str.size()<=4){
        score += 5;
    }
    else if(str.size()<=7){
        score += 10;
    }
    else score += 25;

    int count_lower = 0, count_upper = 0, count_digit = 0, count_symbol = 0;
    for(int i=0; i<str.size(); i++){
        if(islower(str[i])){
            count_lower ++;
        }
        else if(isupper(str[i])){
            count_upper ++;
        }
        else if(isdigit(str[i])){
            count_digit ++;
        }
        else count_symbol ++;
    }
    if(count_lower == 0 && count_upper == 0) score += 0;
    else if((count_lower != 0 && count_upper == 0) || (count_lower == 0 && count_upper != 0)) score += 10;
    else score += 20;

    if(count_digit == 0) score += 0;
    else if(count_digit == 1) score += 10;
    else score += 20;

    if(count_symbol == 0) score += 0;
    else if(count_symbol == 1) score += 10;
    else score += 25;

    if(count_lower != 0&& count_upper != 0 && count_digit != 0 && count_symbol != 0) score += 5;
    else if(((count_lower != 0&& count_upper == 0) || (count_lower == 0&& count_upper != 0)) && count_digit != 0 && count_symbol != 0) score += 3;
    else if(((count_lower != 0&& count_upper == 0) || (count_lower == 0&& count_upper != 0)) && count_digit != 0 && count_symbol == 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 cout << "VERY_WEAK" << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
11-07 13:31
怀化学院 Java
勇敢牛牛不怕难:又疯一个
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务