1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度超2的子串重复
说明:长度超过2的子串
输入描述:
一组或多组长度超过2的子符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG
输入例子:
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000
输出例子:
OK NG NG OK
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String pwd = in.nextLine();
if(pwd.length()<=8||calChar(pwd)==0||calRepeat(pwd)==0){
System.out.println("NG");
continue;
}else{
System.out.println("OK");
continue;
}
}
}
public static int calChar(String pwd){
int numType=0,charType1=0,charType2=0,otherType=0;
for(int i=0;i<pwd.length();i++){
char c = pwd.charAt(i);
if(c>='a'&&c<='z'){
charType1=1;
continue;
}else if(c>='A'&&c<='Z'){
charType2=1;
continue;
}else if(c>='0'&&c<='9'){
numType=1;
continue;
}else{
otherType=1;
continue;
}
}
int num=numType+charType1+charType2+otherType;
return (num>=3)?1:0;
}
public static int calRepeat(String pwd){
for(int i=0;i<pwd.length()-2;i++){
String temp = pwd.substring(i,i+3);
if(pwd.lastIndexOf(temp)>=i+3){
return 0;
}
}
return 1;
}
}