描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度大于2的子串重复
输入描述:
一组或多组长度超过2的字符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入:
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000
输出:
OK NG NG OK
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str =sc.nextLine();
good(str);
}
}
public static void good(String str){
if(str.length()<=8){
System.out.println("NG");
return;
}else{
Boolean flag1=false;
Boolean flag2=false;
Boolean flag3=false;
Boolean flag4=false;
for(int i=0;i<str.length();i++){
if(str.charAt(i)>='A'&&str.charAt(i)<='Z'){
flag1=true;
}
if(str.charAt(i)>='a'&&str.charAt(i)<='z'){
flag2=true;
}
if(str.charAt(i)>='0'&&str.charAt(i)<='9'){
flag3=true;
}
if(!(str.charAt(i)>='A'&&str.charAt(i)<='Z'||
str.charAt(i)>='a'&&str.charAt(i)<='z'||
str.charAt(i)>='0'&&str.charAt(i)<='9')){
flag4=true;
}
}
if(!(flag1&&flag2&&flag3||flag2&&flag3&&flag4||flag1&&flag3&&flag4||flag1&&flag2&&flag4)){
System.out.println("NG");
}else{
if(checkRepeatSubstring(str)){
System.out.println("OK");
}else{
System.out.println("NG");
}
}
}
}
public static boolean checkRepeatSubstring(String password){
for (int i = 0; i < password.length() - 3; i++) {
String s = password.substring(i, i + 3);
String tempStr = password.substring(i + 3, password.length());
if (tempStr.contains(s)) {
return false;
}
}
return true;
}
}