题解 | #密码强度等级#

密码强度等级

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

全部评论

相关推荐

小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
宇算唯航:目测实缴资本不超100W的小公司
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务