题解 | 密码强度等级

密码强度等级

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

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

int daxie,xiaoxie,fuhao,shuzi;

int main() {
    string s;cin>>s;
    int Score = 0;
    int len = s.size();
    for(auto i:s){
        if('a'<=i&&i<='z') xiaoxie++;
        else if('A'<=i&&i<='Z') daxie++;
        else if('0'<=i&&i<='9') shuzi++;
        else fuhao++;
    }
    // 密码长度
    if(len<=4) Score+=5;
    else if(len<=7) Score+=10;
    else Score+=25;
    //字母
    if(daxie==0&&xiaoxie==0) Score+=0;
    else if(daxie==0||xiaoxie==0) Score+=10;
    else Score+=20;
    // 数字
    if(shuzi==0) Score+=0;
    else if(shuzi==1)Score+=10;
    else Score+=20;
    //符号
    if(fuhao==0) Score+=0;
    else if(fuhao==1)Score+=10;
    else Score+=25;
    // 奖励
    if(daxie&&xiaoxie&&fuhao&&shuzi) Score+=5;
    else if((daxie||xiaoxie)&&shuzi&&fuhao) Score+=3;
    else if((daxie||xiaoxie)&&shuzi) Score+=2;
    
    if(Score<25) cout<<"VERY_WEAK";
    else if(Score<50) cout<<"WEAK";
    else if(Score<60) cout<<"AVERAGE";
    else if(Score<70) cout<<"STRONG";
    else if(Score<80) cout<<"VERY_STRONG";
    else if(Score<90) cout<<"SECURE";
    else cout<<"VERY_SECURE";


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

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务