密码验证合格程序
描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
数据范围:输入的字符串长度满足 1≤�≤100 1≤n≤100
输入描述:
一组字符串。
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入:
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000
输出:
OK NG NG OK
1 import java.util.ArrayList; 2 import java.util.HashSet; 3 import java.util.List; 4 import java.util.Scanner; 5 import java.util.Set; 6 7 // 注意类名必须为 Main, 不要有任何 package xxx 信息 8 public class Main { 9 public static void main(String[] args) { 10 Scanner scanner = new Scanner(System.in); 11 while (scanner.hasNextLine()) { 12 boolean isPass = true; 13 String str= scanner.nextLine(); 14 if (str.length()<=8) { 15 isPass = false; 16 } 17 int countA = 0; 18 int countB = 0; 19 int countC = 0; 20 int countD = 0; 21 for (int i = 0; i < str.length(); i++) { 22 char ch = str.charAt(i); 23 if (ch>='a' && ch<='z') { 24 countA=1; 25 } else if (ch>='A' && ch<='Z') { 26 countB=1; 27 } else if (ch>='0' && ch<='9') { 28 countC=1; 29 } else { 30 countD=1; 31 } 32 } 33 if (countA+countB+countC+countD<3) { 34 isPass = false; 35 } 36 List<String> tempList = new ArrayList<>(); 37 Set<String> tempSet = new HashSet<>(); 38 for (int i = 0; i < str.length()-2; i++) { 39 String strA = str.substring(i,i+3); 40 tempList.add(strA); 41 tempSet.add(strA); 42 } 43 if (tempList.size()!=tempSet.size()) { 44 isPass = false; 45 } 46 if (isPass) { 47 System.out.println("OK"); 48 } else { 49 System.out.println("NG"); 50 } 51 } 52 } 53 }