题解 | #密码强度等级#

密码强度等级

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

import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner  sc = new Scanner(System.in);
        char [] arr = sc.nextLine().toCharArray();
        int score = 5;
        if(arr.length>=5 && arr.length<=7){
            score+=5;
        }else if(arr.length>7){
            score+=20;
        }
        int num = 0;
        int low = 0;
        int high = 0;
        int symbol = 0;

        for(char x : arr){
            if(x >='0' && x<'9'){
               num++; 
            }else if(x>='a' && x<='z'){
               low++; 
            }else if(x>='A' && x<='Z'){
               high++; 
            }else if(x>='!' && x<='/'){
               symbol++; 
            }else if(x>=':' && x<='@'){
               symbol++; 
            }else if(x>='[' && x<='_'){
               symbol++; 
            }else if(x>='{' && x<='~'){
               symbol++; 
            }
        }
        //字母
        score += low>0&&high>0 ? 20:low>0||high>0 ?10:0;
        //数字
        score += num>1?20:num==1?10:0;
        //符号
        score += symbol>1?25:symbol==1?10:0;
        if(symbol>0 && num>0 && low>0 && high>0){
            score+=5;
        }else if(num>0 && symbol>0 && (low>0 || high>0)){
             score+=3;
        }else if(num>0 && (low>0 || high>0)){
             score+=2;
        }
        String str;
        if(score >= 90){
            str="VERY_SECURE";
        }else if(score >= 80){
            str="SECURE";
        }else if(score >= 70){
            str="VERY_STRONG";
        }else if(score >= 60){
            str="STRONG";
        }else if(score >= 50){
            str="AVERAGE";
        }else if(score >= 25){
            str="WEAK";
        }else{
            str="VERY_WEAK";
        }
        System.out.println(str);

        
        
        
    }
}
全部评论

相关推荐

秋招end未来可期:个人技能可以去找找别人的参考下优化空间很大,项目也是,项目主要是由由项目能引导面试官考察八股,用什么方法解决了什么问题达到了什么效果,比如oos这东西本质上就是调接口,面试官很难延伸来考察八股。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务