题解 | #密码强度等级#

密码强度等级

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

一次AC,这是我没想到的,无限if else

#include <algorithm>

using namespace std;

int main() {
    string str;
    while(getline(cin,str)){
        int sum = 0;
        int n = str.size();
        bool upalpha=false,lowalpha=false,digit=false,punct=false;
        int digitcnt = 0,punctcnt = 0;
        
        if(n<=4)sum+=5;
        else if(n>4&&n<8)sum+=10;
        else sum+=25;
        for(int i = 0;i<n;i++){
            if(isalpha(str[i])){
                if(isupper(str[i])) upalpha = true;
                else lowalpha = true;
            }
            else if(isdigit(str[i])){
                digit =true;
                digitcnt++;
            }
            else if(ispunct(str[i])){
                punct =true;
                punctcnt++;
            }
        }
        if(upalpha||lowalpha){
            if(upalpha)sum+=10;
            if(lowalpha)sum+=10;
        }
        if(digit){
            if(digitcnt==1)sum+=10;
            else sum+=20;
        }
        if(punct){
            if(punctcnt==1)sum+=10;
            else sum+=25;
        }
        if(upalpha&&lowalpha&&digit&&punct) sum+=5;
        else if(upalpha||lowalpha&&digit&&punct) sum+=3;
        else if(upalpha||lowalpha&&digit) sum+=2;
        if(sum>=90)cout<<"VERY_SECURE"<<endl;
        else if(sum>=80)cout<<"SECURE"<<endl;
        else if(sum>=70)cout<<"VERY_STRONG"<<endl;
        else if(sum>=60)cout<<"STRONG"<<endl;
        else if(sum>=50)cout<<"AVERAGE"<<endl;
        else if(sum>=25)cout<<"WEAK"<<endl;
        else if(sum>=0)cout<<"VERY_WEAK"<<endl;
        
    }
}
全部评论

相关推荐

10-12 19:08
666 C++
花开蝶自来_:技能:听动物叫,让雪豹闭嘴
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务