-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_12.java
More file actions
72 lines (59 loc) · 1.54 KB
/
Copy pathString_12.java
File metadata and controls
72 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package HuaweiCoding;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class String_12 {
public static TreeSet<String> treeSet=new TreeSet<>();
public static boolean passwordCheck(String password) {
if(password.length()<8) {
return false;
}
int characterSmall=0,characterBig=0,digit=0,other=0;
char[] passwordCharArray = password.toCharArray();
for(int i=0;i<passwordCharArray.length;i++) {
if(passwordCharArray[i]>='0' && passwordCharArray[i]<='9') {
digit=1;
continue;
}
else if(passwordCharArray[i]>='a' && passwordCharArray[i]<='z') {
characterSmall=1;
continue;
}
else if(passwordCharArray[i]>='A' && passwordCharArray[i]<='Z') {
characterBig=1;
continue;
}
else {
other=1;
continue;
}
}
if((characterBig+characterSmall+digit+other)<3) {
return false;
}
//判断是否有子串重复
for(int i=0;i<passwordCharArray.length-2;i++) {
String substring = password.substring(i, i+3);
if(password.substring(i+1).contains(substring)) {
return false;
}
}
if(treeSet.contains(password)) {
return false;
}
treeSet.add(password);
return true;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String inputStr = sc.nextLine();
boolean result = passwordCheck(inputStr);
if(result) {
System.out.println("OK");
}else {
System.out.println("NG");
}
}
}
}