HJ87 密码强度等级(c++)

HJ87 密码强度等级(c++),第1张

题目链接:密码强度等级_牛客题霸_牛客网

注意点:

这道题的坑比较多

1.大小写字符都包含的情况:lowletter && upletter,只要字母存在lowletter || upletter

2.判断小写:islower,判断大写isupper(); 判断数字isdigit();

3.奖励机制问题,注意题干要求只能选择一种以大优先,所以if的判断顺序只能从大到小

#include
#include
using namespace std;

int main(){
    string s;
    while(getline(cin, s)){
    int digit = 0;
    int upletter = 0;
    int lowletter = 0;
    int other = 0;
    int sum = 0;
    //密码长度
    int len = s.size();
    if(len <= 4) sum +=5;
    else if(len >= 5 && len <=7 ) sum+=10;
    else if(len >= 8) sum+=25;
    //统计字母,数字,符号个数
    for(int i = 0 ; i < s.size(); ++i){
        //小写字母
        if(islower(s[i])) lowletter++;
        //大写字母
        else if(isupper(s[i])) upletter++;
        //数字
        else if(isdigit(s[i])) digit++;
        //符号
        else other++;
    }
    //全是小(大)写字母,大小写混合字母
    if((lowletter > 0 && upletter == 0) || (upletter > 0 && lowletter == 0)){
        sum += 10;
    } 
    //大小写字母混合
    else if (lowletter > 0 && upletter > 0 ) sum +=20;
    //数字
    if(digit == 1) sum += 10;
    else if(digit > 1) sum += 20;
    //符号
    if(other == 1) sum += 10;
    else if(other > 1) sum+= 25;
    //奖励
    //大小写字母,数字,符号
    if(lowletter > 0 && upletter > 0 && digit > 0 && other > 0) sum += 5;
    //字母,数字,符号
    else if((lowletter > 0 || upletter > 0) && (digit > 0) && (other > 0)) sum += 3;
    //字母和数字
    else if((lowletter > 0 || upletter > 0) && (digit > 0)) sum += 2;
    //评分
    if(sum >=90) cout<<"VERY_SECURE"<=80) cout<<"SECURE"<=70) cout<<"VERY_STRONG"<=60) cout<<"STRONG"<=50) cout<<"AVERAGE"<=25) cout<<"WEAK"<

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/577668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)