package com.patience.interview.huawei;
import java.io.IOException;
import java.util.Scanner;
/**
* 校验密码的正确性
* @author Green.Gee
* @date 2022/8/15 14:24
* @email green.gee.lu@gmail.com
*/
public class AuthPwd {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
/**
* 正则表达式
* 长度 8
* 大小写字母
* 数字
* 其它符号 排除 空格和换行
* 不能有大于长度2的子串重复
*/
while(in.hasNextLine()){
String line = in.nextLine();
char [] chars = line.toCharArray();
if(chars.length > 8){
int a = 0,b = 0,c = 0,d = 0;
boolean err = false;
for (char i : chars){
if(i == ' ' || i == '\n') {
err = true;
break;
}else if(i >= '0' && i <= '9'){
a = 1;
}else if(i >= 'a' && i <= 'z'){
b = 1;
}else if(i >= 'A' && i <= 'Z'){
c = 1;
}else{
d = 1;
}
}
if(err){
System.out.println("NG");
}else{
if((a + b + c + d) >= 3){
if(reStr(line)){
System.out.println("OK");
}else{
System.out.println("NG");
}
}else{
System.out.println("NG");
}
}
}else{
System.out.println("NG");
}
}
}
// 重复
private static boolean reStr(String s) {
for (int i = 3; i < s.length(); i++) {
if (s.substring(i).contains(s.substring(i - 3, i))) {
return false;
}
}
return true;
}
}
校验密码的正确性 算法java
于 2022-08-15 15:18:11 首次发布