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

密码验证合格程序

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

import java.util.Scanner;
import java.util.*;
import java.util.regex.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String sinput = in.nextLine();
            if (null == sinput || sinput.length() < 9) {
                System.out.println("NG");
                continue;
            }
            Pattern p = Pattern.compile("[a-z]");
            int count = 0;
            if (p.matcher(sinput).find()) {
                count++;
            }
            if (Pattern.compile("[A-Z]").matcher(sinput).find()) {
                count++;
            }
            if (Pattern.compile("\\d").matcher(sinput).find()) {
                count++;
            }
            if (Pattern.compile("[^a-zA-Z0-9]").matcher(sinput).find()) {
                count++;
            }
            if (count < 3) {
                System.out.println("NG");
                continue;
            }
            //不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
            //校验是否有重复子串
            Boolean f = false;
            for (int i = 0; i < sinput.length() - 3; i++) {
                String pipei = sinput.substring(i, i + 3);
                String shengyu = sinput.substring(i + 3, sinput.length());
                if (shengyu.contains(pipei)) {
                    System.out.println("NG");
                    f = true;
                    break;
                }
            }
            if (f) {
                continue;
            }
            System.out.println("OK");
        }
    }
}

全部评论

相关推荐

八股刚起步,看了javaguide,小林coding,还有面渣,感觉面渣是体验最好的,请问只看面渣够用吗,有不完善的需要补吗?
码农索隆:先背最基础的知识,然后理解情景题,现在面试大多数喜欢问情景题,更考验面试者的基础和临场发挥情况
点赞 评论 收藏
分享
身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
小浪_coder:深圳除了一些计算机,UI设计,金融类等一些可以月薪过万的工作之外, 认识很多朋友做运营,营销,文员的工作, 月薪基本都在4-6K左右,还有大把人在干
点赞 评论 收藏
分享
昨天 10:44
青岛工学院 Java
一表renzha:人家这不是写着1~3年吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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