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

密码验证合格程序

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String a;
        char[] chs;
        int i, j, n1, n2, n3, n4;
        boolean repet1;
        try {
            while ((a = r.readLine()) != null && !a.isEmpty()) {
                chs = a.toCharArray();
                if (chs.length <= 8) {
                    System.out.println("NG");
                    continue;
                }
                i = 0;
                n1 = 0;
                n2 = 0;
                n3 = 0;
                n4 = 0;
                while (i < chs.length) {
                    if (((chs[i] - 'a') | ('z' - chs[i])) > 0) n1 = 1;
                    else if (((chs[i] - 'A') | ('Z' - chs[i])) > 0) n2 = 1;
                    else if (((chs[i] - '0') | ('9' - chs[i])) > 0) n3 = 1;
                    else n4 = 1;
                    i++;
                }
                if ((n1 + n2 + n3 + n4) < 3) {
                    System.out.println("NG");
                    continue;
                }
                i = 2;
                repet1 = false;
                while (i < chs.length - 1) {
                    j = i + 1;
                    while (j < chs.length) {
                        if (chs[i - 2] == chs[j - 2] && chs[i - 1] == chs[j - 1] && chs[i] == chs[j]) {
                            repet1 = true;
                            break;
                        }
                        j++;
                    }
                    if (repet1) break;
                    i++;
                }
                if (repet1) {
                    System.out.println("NG");
                    continue;
                }
                System.out.println("OK");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
北漂的牛马人:211佬,包进的,可能是系统问题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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