题解 | #密码强度等级# 全是 if

密码强度等级

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

#include <iostream>
using namespace std;

int main() {
    string s;
    cin >> s;
    int score=0,len=s.size(),letter_a=0,letter_A=0,num=0,symbol=0;
    if(len<=4){
        score += 5;
    }else if(len >=5 && len <=7){
        score += 10;
    }else{
        score += 25;
    }

    for(int i=0; i<len; i++){
        if(s[i] >= 'a' && s[i] <= 'z'){
            letter_a += 1;
        }
        else if(s[i] >= 'A' && s[i] <= 'Z'){
            letter_A += 1;
        }
        else if(s[i] >= '0' && s[i] <= '9'){
            num += 1;
        }else if((s[i] >= 0x21 && s[i] <= 0x2F) || (s[i] >= 0x3A && s[i] <= 0x40)
         || (s[i] >= 0x5B && s[i] <= 0x60) || (s[i] >= 0x7B && s[i] <= 0x7E)){
            symbol += 1;
        }
    }

    if((letter_a>0 && letter_A==0) || (letter_A>0 && letter_a==0)){
        score += 10;
    }else if(letter_a>0 && letter_A>0){
        score += 20;
    }

    if(num == 1){
        score += 10;
    }else if(num > 1){
        score += 20;
    }

    if(symbol == 1){
        score += 10;
    }else if(symbol > 1){
        score += 25;
    }

    if(letter_A>0 && letter_a>0 && num>0 && symbol>0){
        score += 5;
    }else if((letter_A >0 || letter_a > 0) && num>0 && symbol>0){
        score += 3;
    }else if((letter_A >0 || letter_a > 0) && num>0){
        score += 2;
    }
    // cout << score << endl;
    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;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务