美团笔试密码匹配
不知道什么边界没有考虑到,只能AC91%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
sc.nextLine();
String[] str = new String[n];
for (int i = 0; i < n; i ++) {
str[i] = sc.nextLine();
}
for (int i = 0; i < n; i ++ ) {
System.out.println(match(str[i]));
}
}
}
public static String match(String str) {
String res = null;
if (str.length() < 8) {
res = "NO";
} else {
String regex = "^[^0-9]\\w*";
if (!str.matches("[0-9A-Za-z]+")) {
res = "NO";
} else if (!str.matches(regex)) {
res = "NO";
} else if (str.matches("\\w*[0-9]+\\w*") && (str.matches("\\w*[a-z]+\\w*") || str.matches("\\w*[A-Z]+\\w*"))){
res = "YES";
} else {
res = "NO";
}
}
return res;
}
}
#美团#