题解 | 密码强度等级

密码强度等级

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNext()) {
            String pwd = in.nextLine();

            int numCount = 0;
            int upCharCount = 0;
            int lowCharCount = 0;
            int zfCount = 0;

            for (int i = 0; i < pwd.length(); i++) {
                char c = pwd.charAt(i);

                if (Character.isDigit(c)) {
                    numCount++;
                    continue;
                }

                if (c >= 'a' && c <= 'z') {
                    lowCharCount = 1;
                    continue;
                }
                if (c >= 'A' && c <= 'Z') {
                    upCharCount = 1;
                    continue;
                }
                zfCount++;
            }

            int score = 0;
            if (pwd.length() <= 4) {
                score += 5;
            } else if (pwd.length() <= 7) {
                score += 10;
            } else {
                score += 25;
            }

            if (lowCharCount + upCharCount == 1) {
                score += 10;
            } else if (lowCharCount + upCharCount == 2) {
                score += 20;
            }

            if (numCount == 1) {
                score += 10;
            }
            if (numCount > 1) {
                score += 20;
            }

            if (zfCount == 1) {
                score += 10;
            }
            if (zfCount > 1) {
                score += 25;
            }

            if ((upCharCount + lowCharCount) == 2 && numCount > 0 && zfCount >= 0) {
                score += 5;
            } else if ((upCharCount + lowCharCount) == 1 && numCount > 0 && zfCount >= 0) {
                score += 3;
            } else if ((upCharCount + lowCharCount) == 1 && numCount > 0) {
                score += 2;
            }

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

全部评论

相关推荐

不知名bang:感觉三个项目可以融在一起,比如上层是用手写的epoll,然后到tcp聊天层,然后你写了一个后台监控(不过我也不懂c++,但是感觉写一个大项目比三个小项目要好)
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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