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

密码验证合格程序

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");
            }
        }
    }
}

全部评论

相关推荐

Rena1ssance_:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
在开会的单身狗很有一套:学院本被想着这么快有面试,而且简历废话太多了 那些在校经历什么荣誉什么的企业不关心
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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