题解 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import java.util.HashSet; import java.util.Scanner; public class HJ20 { public static void main(String[] args) { Scanner input=new Scanner(System.in); while (input.hasNextLine()) { String string=input.nextLine(); if (string.length()>8) { int count=0; if (string.matches(".*[A-Z].*")) { count=count+1; } if (string.matches(".*[a-z].*")) { count=count+1; } if (string.matches(".*[0-9].*")) { count=count+1; } if (string.matches(".*[^a-zA-Z0-9].*")) { count=count+1; } // System.out.println(count); if (count>=3) { HashSet<String> set=new HashSet<>(); for (int i = 0; i < string.length()-3; i++) { String sub=string.substring(i,i+3); if(set.add(sub)) { }else { System.out.println("NG"); return; } } System.out.println("OK"); }else { System.out.println("NG"); } } else { System.out.println("NG"); } } } }