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

密码验证合格程序

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

import java.util.Scanner;
import java.util.regex.Pattern;

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

        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.length() < 9) {
                System.out.println("NG");
                continue;
            }
            int count = 0;
            Pattern p1 = Pattern.compile("[A-Z]");
            if (p1.matcher(line).find()) {
                count++;
            }
            Pattern p2 = Pattern.compile("[a-z]");
            if (p2.matcher(line).find()) {
                count++;
            }
            Pattern p3 = Pattern.compile("[0-9]");
            if (p3.matcher(line).find()) {
                count++;
            }
            Pattern p4 = Pattern.compile("[^A-Za-z0-9 \n\r]");
            if (p4.matcher(line).find()) {
                count++;
            }

            if (count < 3) {
                System.out.println("NG");
                continue;
            }

            // 子串重复
            boolean b = true;
            for (int j = 3; j < line.length(); j++) {
                if (line.substring(j).contains(line.substring(j - 3, j))) {
                    b = false;
                    break;
                }
            }

            if (b) {
                System.out.println("OK");
            } else {
                System.out.println("NG");
            }
        }
    }
}

全部评论

相关推荐

07-28 16:10
门头沟学院 Java
连笔试都没有就直接挂了&nbsp;这是学历厂吗两段大厂实习一段中厂一点机会都没有吗真的很难绷
xiaolihuam...:校招挂了,然后反手给我捞了个社招
投递虾皮信息等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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