题目描述:
密码要求:1.长度超过8位。2.包括大小写字母,数字,其它符号,以上四种至少三种。3.不能有相同长度超2的子串重复。
输入描述:一组或多组长度超2的字符串。每组占一行。
输出描述:如果符合要求输出:OK;否则输出NG。
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.next();
if(cond1(str)&&cond2(str)&&cond3(str)){
System.out.println("OK");
}else{
System.out.println("NG");
}
}
sc.close();
}
//长度超过8位
public static boolean cond1(String str){
if(str.length()>8){
return true;
}
return false;
}
//包括大小写字母、数字、其它符号,至少三种。
public static boolean cond2(String str){
int count=0;
boolean falgnum=false;
boolean flagsmall=false;
boolean flagupp=false;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
if(c>='0'&&c<='9'){
falgnum=true;
}
if(c>='a'&&c<='z'){
flagsmall=true;
}
if(c>='A'&&c<='Z'){
flagupp=true;
}
}
return (falgnum&&flagsmall)||(falgnum&&flagupp)||(flagsmall&&flagupp);
}
//不能有相同的子串重复
public static boolean cond3(String str){
for(int i=0;i<str.length()-4;i++){
String substr=str.substring(i,i+3);
for(int j=i+1;j<str.length()-4;j++){
String strsub=str.substring(j,j+3);
if(substr.equals(strsub)){
return false;
}
}
}
return true;
}
}