题解 | #密码强度等级#

密码强度等级

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

#include <climits>
#include <iostream>
using namespace std;

string flat(int num)
{
    if (num >= 90) return "VERY_SECURE";
    else if (num < 90 && num >= 80) return "SECURE";
    else if (num < 80 && num >= 70) return "VERY_STRONG";
    else if (num < 70 && num >= 60) return "STRONG";
    else if (num < 60 && num >= 50) return "AVERAGE";
    else if (num < 50 && num >= 25) return "WEAK";
    else if (num < 25 && num >= 0)  return "VERY_WEAK";
    else {return "ERROR";}
}

int ComputeScore(string s)
{
    int score1 = 0, score2 = 0, score3 = 0, score4 = 0, score5 = 0;
    for (int i = 0; i < s.length(); i++){
        if (score1 < 10 && s[i] >= 'a' && s[i] <= 'z'){
            score1 = 10;
            continue;
        }
        
        if (score2 < 10 && s[i] >= 'A' && s[i] <= 'Z'){
            score2 = 10;
            continue;
        }

        if (score3 < 20 && s[i] >= '0' && s[i] <= '9' ){
            score3 += 10;
            continue;
        }

        if (score4 < 25 && (s[i] >= 0x21 && s[i] <= 0x2F) 
            || (s[i] >= 0x3A && s[i] <= 0x40)
            || (s[i] >= 0x5B && s[i] <= 0x60)
            || (s[i] >= 0x7B && s[i] <= 0x7E))
        {
            if (score4 < 10) score4 += 10;
            else {score4 = 25;}
            continue;
        }
    }
    if ((score1 != 0 || score2 != 0) && score3 != 0){
        score5 += 2;
        if (score4 != 0){
            score5 += 1;
            if (score1 != 0 && score2 != 0){
                score5 += 2;
            }
        }
    }
    // cout << score1 << ","<< score2 << ","  << score3  << "," << score4 << ","  << score5 <<endl;
    // cout << ans <<endl;
    return score1 + score2 + score3 + score4 + score5;
}

int main() {
    string input,ans;
    int score = INT_MIN;
    while (cin >> input){
        int len = input.length();

        if (len <= 4)                 score = 5;
        else if (len > 4 && len <= 7) score = 10;
        else if (len > 7)             score = 25;
        else {}
        // cout <<score <<endl;

        int num = ComputeScore(input);
        ans = flat(score +  num);
    }
    cout << ans << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

头像
10-14 23:01
已编辑
中国地质大学(武汉) Java
CUG芝士圈:虽然是网上的项目,但最好还是包装一下,然后现在大部分公司都在忙校招,十月底、十一月初会好找一些。最后,boss才沟通100家,别焦虑,我去年暑假找第一段实习的时候沟通了500➕才有面试,校友加油
点赞 评论 收藏
分享
粗心的雪碧不放弃:纯学历问题,我这几个月也是一直优化自己的简历,后来发现优化到我自己都觉得牛逼的时候,发现面试数量也没有提升,真就纯学历问题
点赞 评论 收藏
分享
美团 后端开发 总包n(15%是股票)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务