题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()){ String str = in.nextLine(); char[] chars = str.toCharArray(); int cnt = 0; //判断长度 if(chars.length > 8){ ++cnt; } //判断大小写、数字和符号 int isLow = 0, isUp = 0, isDig = 0, isLetter = 0; for(char ch : chars){ if(Character.isLowerCase(ch)){ isLow = 1; } if(Character.isUpperCase(ch)){ isUp = 1; } if(Character.isDigit(ch)){ isDig = 1; } if(!Character.isLetterOrDigit(ch)){ isLetter = 1; } if(isLow + isUp + isDig + isLetter >= 3){ ++cnt; break; } } //判断子串 int sign = 1; for(int i = 0; i < str.length() -2; ++i){ String s = str.substring(i, i + 3); if(str.substring(i + 1).contains(s)){ sign = 0; break; } } cnt += sign; if(cnt >= 3){ System.out.println("OK"); continue; } System.out.println("NG"); } } }