题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
if(valid(in.nextLine())){
System.out.println("OK");
}
else{
System.out.println("NG");
}
}
}
public static boolean valid(String str){
if(str.length() <= 8){
return false;
}
int[] valid = new int[4];
char[] cs = str.toCharArray();
for(char c : cs){
if( c == ' ' || c == '\n'){
return false;
}
else if(c >= '0' && c <= '9' ){
valid[0]++;
}
else if(c >= 'a' && c <= 'z'){
valid[1]++;
}
else if(c >= 'A' && c <= 'Z'){
valid[2]++;
}
else{
valid[3]++;
}
}
int count = 0;
for(int i = 0; i < 4; i++){
if(valid[i] != 0){
count++;
}
}
if(count < 3){
return false;
}
for(int i = 0; i < str.length() - 3; i++){
String tmp_1 = str.substring(i,i+3);
String tmp_2 = str.substring(i + 3);
if(tmp_2.contains(tmp_1)){
return false;
}
}
return true;
}
}
三奇智元机器人科技有限公司公司福利 86人发布
