题解 | #Where in 和Not in#

密码强度等级

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

import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int score = 0; String password = in.nextLine(); int len = password.length(); if(len <= 4) {score += 5;} else if(len <= 7){ score += 10; }else { score += 25; } int uper = 0; int lower = 0; int num = 0; int nch = 0; for(int i = 0;i < len;i ++){ if(password.charAt(i) <= '9' && password.charAt(i) >= '0') { num ++; }else if(password.charAt(i) <= 'Z' && password.charAt(i) >= 'A'){ uper = 1; }else if(password.charAt(i) <= 'z' && password.charAt(i) >= 'a'){ lower =1; } else{ nch ++; }

        }
        if(num >=2){
            score += 20;
        }else if(num > 0){
            score += 10;
        }
        if(uper+lower == 2){
            score +=20;
        }else if(uper+lower == 1){
            score += 10;
        }
        if(nch >=2){
            score += 25;
        }else if(nch == 1){
            score += 10;
        }
        if(num > 0 && nch > 0 && uper+lower == 0){
            score += 2;
        }
        if(num > 0 && nch >0 && uper+ lower == 1){
            score += 3;
        }
        if(num > 0 && nch >0 && uper+ lower == 2){
            score += 5;
        }
        grade(score);
    }
}
public static void grade(int score){
    if(score >= 90){
        System.out.println("VERY_SECURE");
    }else if(score >= 80){
        System.out.println("SECURE");
    }else if(score >= 70){
        System.out.println("VERY_STRONG");
    }else if(score >= 60){
        System.out.println("STRONG");
    }else if(score >= 50){
        System.out.println("AVERAGE");
    }else if(score >= 25){
        System.out.println("WEAK");
    }else {
        System.out.println("VERY_WEAK");
    }
    
}

}

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

程序员牛肉:这一眼假啊,基本上都是骗人的,不然就涉及到职位贪腐了,就像之前华为的OD事件,看你运气好不好了
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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