题解 | #密码强度等级#

密码强度等级

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

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

int lengthPoint(string str){
    int res = 0;
    // 1. 判断长度
    int len = str.length();
    if(len <= 4){
        res = 5;
    }else if(len <= 7){
        res = 10;
    }else{
        res = 25;
    }

    return res;
}

int cntAlphaPoint(string str){
    int cnt = 0;
    int upper = 0;
    int lower = 0;
    int res = 0;
    for(auto it : str){
        if(isalpha(it)){
            cnt ++;
            if(isupper(it)){
                upper++;
            }else{
                lower++;
            }
        }
    }
    if(cnt == 0){
        res = 0;
    }else if(upper == 0 || lower == 0){
        res = 10;
    }else{
        res = 20;
    }
    return res;
}

int cntDigitPoint(string str){
    int cnt = 0;
    int res = 0;
    for(auto it : str){
        if(isdigit(it)){
            cnt ++;
        }
    }
    if(cnt == 0){
        res = 0;
    }else if(cnt == 1){
        res = 10;
    }else{
        res = 20;
    }
    return res;
}

int cntSimbolPoint(string str){
    int cnt = 0;
    int res = 0;
    for(auto it : str){
        if(ispunct(it)){
            cnt ++;
        }
    }
    if(cnt == 0){
        res = 0;
    }else if(cnt == 1){
        res = 10;
    }else{
        res = 25;
    }
    return res;
}

int cntElse(int a, int b, int c, int d){
    int res = 0;
    if(b == 20 && c >= 10 && d >= 10){
        res = 5;
    }else if(b >= 10 && c >= 10 && d >= 10){
        res = 3;
    }else if(b >= 10 && c >= 10){
        res = 2;
    }
    return res;
}
void printPoint(int total){
    if(total >= 90){
        cout << "VERY_SECURE" << endl;
    }else if(total >= 80){
        cout << "SECURE" << endl;
    }else if(total >= 70){
        cout << "VERY_STRONG" << endl;
    }else if(total >= 60){
        cout << "STRONG" << endl;
    }else if(total >= 50){
        cout << "AVERAGE" << endl;
    }else if(total >= 25){
        cout << "WEAK" << endl;
    }else if(total >= 0){
        cout << "VERY_WEAK" << endl;
    }
}
int main() {
    string str;
    while (getline(cin, str)) { // 注意 while 处理多个 case
        int a = 0, b = 0, c = 0, d = 0, e = 0, total = 0; 
        
        a = lengthPoint(str);
        b = cntAlphaPoint(str);
        c = cntDigitPoint(str);
        d = cntSimbolPoint(str);
        e = cntElse(a,b,c,d);
        total = a+b+c+d+e;

        printPoint(total);
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

泥给路哒油:真的不行了,以后趋势就是没有前后端职位之分了,我现在就是什么都干,有了ai就能干全栈,md年初目送一大堆同事毕业
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
9225次浏览 83人参与
# 你的实习产出是真实的还是包装的? #
1689次浏览 40人参与
# 巨人网络春招 #
11300次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7416次浏览 42人参与
# 简历第一个项目做什么 #
31519次浏览 327人参与
# 重来一次,我还会选择这个专业吗 #
433317次浏览 3926人参与
# MiniMax求职进展汇总 #
23762次浏览 308人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186924次浏览 1120人参与
# 牛客AI文生图 #
21402次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152278次浏览 887人参与
# 研究所笔面经互助 #
118859次浏览 577人参与
# 简历中的项目经历要怎么写? #
309978次浏览 4189人参与
# AI时代,哪些岗位最容易被淘汰 #
63343次浏览 799人参与
# 面试紧张时你会有什么表现? #
30482次浏览 188人参与
# 你今年的平均薪资是多少? #
212996次浏览 1039人参与
# 你怎么看待AI面试 #
179816次浏览 1231人参与
# 高学历就一定能找到好工作吗? #
64302次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76425次浏览 374人参与
# 我的求职精神状态 #
447969次浏览 3128人参与
# 正在春招的你,也参与了去年秋招吗? #
363209次浏览 2637人参与
# 腾讯音乐求职进展汇总 #
160568次浏览 1110人参与
# 校招笔试 #
470199次浏览 2962人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务