题解 | #密码强度等级#

密码强度等级

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

import java.util.List;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Collectors;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String nextLine = in.nextLine();
            if (Objects.isNull(nextLine) || nextLine.equals("")) {
                break;
            }

            int point = 0;
            if (nextLine.length() <= 4) {
                point += 5;
            }
            if (nextLine.length() <= 7 && nextLine.length() >= 5) {
                point += 10;
            }
            if (nextLine.length() >= 8) {
                point += 25;
            }
            List<String> strings = nextLine.chars()
                .mapToObj(item -> "" + (char) item)
                .collect(Collectors.toList());
            if ((strings.stream()
                .anyMatch(item -> item.matches("[a-z]")) && strings.stream()
                .noneMatch(item -> item.matches("[A-Z]"))) || (strings.stream()
                .noneMatch(item -> item.matches("[a-z]")) && strings.stream()
                .anyMatch(item -> item.matches("[A-Z]")))) {
                point = point + 10;
            }
            if((strings.stream()
                .anyMatch(item -> item.matches("[a-z]")) && strings.stream()
                .anyMatch(item -> item.matches("[A-Z]")))){
                point = point + 20;
            }
            long count = strings.stream()
                .filter(item -> item.matches("[0-9]"))
                .count();
            if(count==1){
                point=point+10;
            }
            if(count>1){
                point+=20;
            }
            long count1 = strings.stream()
                .filter(item -> item.matches("[^0-9a-zA-Z]"))
                .count();
            if(count1==1){
                point+=10;
            }
            if(count1>1){
                point+=25;
            }
            long numCount = strings.stream()
                .filter(item -> item.matches("[0-9]"))
                .count();
            long lowCount = strings.stream()
                .filter(item -> item.matches("[a-z]"))
                .count();
            long upperCount = strings.stream()
                .filter(item -> item.matches("[A-Z]"))
                .count();
            if(upperCount > 0 && lowCount > 0 && numCount > 0 && count1 > 0){
                point += 5;
            }else if((upperCount > 0 && numCount > 0 && count1 > 0) || (lowCount > 0 && numCount > 0 && count1 > 0)){
                point += 3;
            }else if((upperCount > 0 && numCount > 0) || (lowCount > 0 && numCount > 0)){
                point += 2;
            }

            if (point >= 90) {
                System.out.println("VERY_SECURE");
            }
            if (point >= 80 && point < 90) {
                System.out.println("SECURE");
            }
            if (point >= 70 && point < 80) {
                System.out.println("VERY_STRONG");
            }
            if (point >= 60 && point < 70) {
                System.out.println("STRONG");
            }
            if (point >= 50 && point < 60) {
                System.out.println("AVERAGE");
            }
            if (point >= 25 && point < 50) {
                System.out.println("WEAK");
            }
            if (point >= 0 && point < 25) {
                System.out.println("VERY_WEAK");
            }
        }
    }
}

全部评论

相关推荐

刷牛客的单身狗很认真:全国可飞,支持007 上班时间,是吧?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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