题解 | #密码强度等级#

密码强度等级

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

#include <iostream>
using namespace std;

int main() {
    string s;
    getline(cin, s);
    int l = 0;
    int num_number = 0;
    int num_alb_low = 0;
    int num_alb_high = 0;
    int num_symbol = 0;
    //长度
    if(s.size()==0){
        cout<<"Very_Weak";
        return 0;
    }

    if (s.size() <= 4) {
        l += 5;
    } else if (s.size() >= 5 && s.size() <= 7) {
        l += 10;
    } else {
        l += 25;
    }

    for (auto x : s) {
        if (x >= '0' && x <= '9') {
            num_number++;
            continue;
        }
        if (x >= 'a' && x <= 'z') {
            num_alb_low++;
            continue;
        }
        if (x >= 'A' && x <= 'Z') {
            num_alb_high++;
            continue;
        }
        if ((x >= '!' && x <= '/') || (x >= ':' && x <= '@') || (x >= '[' &&
                x <= '`') || (x >= '{' && x <= '~')) {
            num_symbol++;
            continue;
        }
    }
    //数字
    if (num_number == 0) {
    } else if (num_number == 1) {
        l += 10;
    } else {
        l += 20;
    }
    //字母
    if(num_alb_high+num_alb_low==0){
    }else if((num_alb_low >=1 &&num_alb_high==0)|| (num_alb_high >=1&&num_alb_low==0)){
        l += 10;
    }else if(num_alb_low>=1&&num_alb_high>=1){
        l+=20;
    }
    //符号
    if (num_symbol == 0) {
    } else if (num_symbol == 1) {
        l += 10;
    } else {
        l += 25;
    }

    //奖励
    if (num_alb_low >= 1 && num_alb_high >= 1 && num_number >= 1 &&
            num_symbol >= 1) {
        l += 5;
    } else {
        if ((num_alb_high + num_alb_low) >= 1 && num_number >= 1 && num_symbol >= 1) {
            l += 3;
        } else {
            if ((num_alb_high + num_alb_low) >= 1 && num_number >= 1) {
                l += 2;
            }
        }
    }
        if (l >= 90) {
            cout << "VERY_SECURE";
        } else if (l >= 80) {
            cout << "SECURE";
        } else if (l >= 70) {
            cout << "VERY_STRONG";
        } else if (l >= 60) {
            cout << "STRONG";
        } else if (l >= 50) {
            cout << "AVERAGE";
        } else if (l >= 25) {
            cout << "WEAK";
        } else if (l >= 0) {
            cout << "VERY_WEAK";
        }
    }
// 64 位输出请用 printf("%lld")

又臭又长

全部评论

相关推荐

02-03 12:20
门头沟学院 Java
一天代码十万三:你这个简历东西太杂了,根本看不出你想投什么岗位
点赞 评论 收藏
分享
什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务