题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner fzhinput = new Scanner(System.in);
while (fzhinput.hasNextLine()) {
boolean result = true;
boolean ff = true;
int a = 0, b = 0, c = 0, d = 0, sz = 0;
String fzhpassword = fzhinput.nextLine();
if (fzhpassword.length() <= 8 || fzhpassword.contains(" ")) {
result = false;
}
for (int i = 0; i < fzhpassword.length(); i++) {
char ch = fzhpassword.charAt(i);
if (ch >= 'A' && ch <= 'Z') {
a = 1;
} else if (ch >= 'a' && ch <= 'z') {
b = 1;
} else if (ch >= '0' && ch <= '9') {
c = 1;
} else {
d = 1;
}
}
sz = a + b + c + d;
Set<String> stackstore = new HashSet<>();
for(int i=0;i<fzhpassword.length()-2;i++){
for(int l=3;i+l<=fzhpassword.length();l++ ){
String zfc = fzhpassword.substring(i,i+l);
if(stackstore.contains(zfc)){
ff=false;
}
stackstore.add(zfc);
}
}
if (sz >= 3 && result && ff) {
System.out.println("OK");
} else {
System.out.println("NG");
}
}
}
}
查看24道真题和解析