题解 | #密码强度等级#

密码强度等级

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")

全部评论

相关推荐

努力成为C语言高手:质疑大祥老师,理解大祥老师,成为大祥老师
点赞 评论 收藏
分享
10-09 22:05
666 C++
找到工作就狠狠玩CSGO:报联合国演讲,报电子烟设计与制造
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务