题解 | #密码强度等级#

密码强度等级

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

#include <bits/stdc++.h>
using namespace std;

int main(){
    vector<string> v={"VERY_SECURE","SECURE","VERY_STRONG","STRONG","AVERAGE","WEAK","VERY_WEAK"};
    string m;
    int grand;
    while(cin>>m){
        grand=0;
        int salpha=0,balpha=0,numb=0;
        
        for(int i=0;i<m.size();++i){
            if(m[i]>='a'&&m[i]<='z') salpha++;
            else if(m[i]>='A'&&m[i]<='Z') balpha++;
            else if(m[i]>='0'&&m[i]<='9') numb++;
        }
        
        //密码长度得分
        if(m.size()<=4) grand+=5;
        else if(m.size()>=8) grand+=25;
        else grand+=10;
        
        //字母
        if(salpha==0&&balpha==0) ;
        else if(salpha==0||balpha==0) grand+=10;
        else grand+=20;
        
        //数字
        if(numb==0);
        else if(numb>1) grand+=20;
        else grand+=10;
        
        //符号
        if(m.size()-salpha-balpha-numb==0) ;
        else if(m.size()-salpha-balpha-numb==1) grand+=10;
        else grand+=25;
        
        //奖励
        if(salpha>0&& balpha>0&&numb>0&&m.size()-salpha-balpha-numb>0) grand+=5;
        else if((salpha==0||balpha==0)&&m.size()-salpha-balpha-numb>0) grand+=3;
        else grand+=2;
            
        if(grand>=90) cout<<v[0]<<endl;
        else if(grand>=80) cout<<v[1]<<endl;
        else if(grand>=70) cout<<v[2]<<endl;
        else if(grand>=60) cout<<v[3]<<endl;
        else if(grand>=50) cout<<v[4]<<endl;
        else if(grand>=25) cout<<v[5]<<endl;
        else cout<<v[6]<<endl;     
    }
    return 0;
}
全部评论

相关推荐

一名愚蠢的人类:多少games小鬼留下了羡慕的泪水
投递荣耀等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务