1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public class HJ020 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
System.out.println(check(sc.nextLine()) ? "OK" : "NG");
}
}
public static boolean check(String pwd) {
if (pwd.length() <= 8) {
return false;
}
boolean[] flags = new boolean[4];
for (char c : pwd.toCharArray()) {
if (c >= 'a' && c <= 'z') {
flags[0] = true;
} else if (c >= 'A' && c <= 'Z') {
flags[1] = true;
} else if (Character.isDigit(c)) {
flags[2] = true;
} else if (!flags[3]) {
flags[3] = true;
}
}
int cnt = 0;
for (boolean flag : flags) {
if (flag) cnt++;
}
if (cnt < 3) {
return false;
}
for (int i = 0; i < pwd.length() - 5; i++) {
for (int j = i + 3; j < pwd.length() - 2; j++) {
if (pwd.substring(i, i + 3).equals(pwd.substring(j, j + 3))) {
return false;
}
}
}
return true;
}
}