题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

import java.util.Scanner;

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

        scanner.useDelimiter("\n");
        

        while (scanner.hasNext()) {
            String S = scanner.next();
            boolean AA = true;
            byte ch = 0;
            if (S.length() <= 8) {
                System.out.println("NG");
                continue;
            }
            char[] chars = S.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                char c = chars[i];
                if (zifuA(c) && ((ch & 1) == 0)) {
                    ch += 1;
                } else if (zifua(c) && ((ch & 2) == 0)) {
                    ch += 2;
                } else if (zifu0(c) && ((ch & 4) == 0)) {
                    ch += 4;
                } else if (zifuOther(c) && ((ch & 8) == 0)) {
                    ch += 8;
                }
                if (i <= chars.length - 6 &&
                        S.substring(i + 3).contains(S.substring(i, i + 3))) {
                    System.out.println("NG");
                    AA = false;
                    break;
                }
            }
            if (!AA) {
                continue;
            }
            if ((ch & 1) + ((ch & 2)>>1) + ((ch & 4)>>2) + ((ch & 8)>>3) < 3) {
                System.out.println("NG");
                continue;
            }

            System.out.println("OK");
        }
    }

    public static boolean zifuA(char c) {
        return  (c >= 'A' && c <= 'Z');
    }

    public static boolean zifua(char c) {
        return (c >= 'a' && c <= 'z');
    }

    public static boolean zifu0(char c) {
        return  (c >= '0' && c <= '9');
    }

    public static boolean zifuOther(char c) {
        return !(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' &&
                c <= '9');
    }



}

全部评论

相关推荐

希望被捞的猫头鹰很理智:大概率待遇低怕硕士跑路
点赞 评论 收藏
分享
03-07 13:32
门头沟学院 C++
D0cC:你是本科生吗,太厉害了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务