题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
import java.awt.List; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.DateFormat; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.function.Function; import java.util.function.IntFunction; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { if (str.length() < 8) { System.out.println("NG"); continue; } char[] chars = str.toCharArray(); int flag_number = 0; int flag_a = 0; int flag_A = 0; int flag_o = 0; for (char aChar : chars) { if (aChar >= '0' && aChar <= '9') { flag_number = 1; continue; } if ((aChar >= 'a' && aChar <= 'z')) { flag_a = 1; continue; } if ((aChar >= 'A' && aChar <= 'Z')) { flag_A = 1; continue; } if (aChar != ' ' && aChar != '\n') { flag_o = 1; } } if (flag_a + flag_A + flag_o + flag_number < 3) { System.out.println("NG"); continue; } int max = 0; for (int i = 0; i < chars.length; i++) { char aChar = chars[i]; int j = i; ArrayList<Integer> al = new ArrayList<>(); for ( j = i + 3; j < chars.length; j++) { if (aChar == chars[j]) { al.add(j); } } if (al.size() != 0) { int temp = 0; while (temp != al.size()) { int y = al.get(temp); temp++; int count = 0; int x = i; while (chars[x] == chars[y]) { count++; x++; y++; if (y >= chars.length - 1) { break; } } if (count > max) { max = count; } } } } if (max > 2) { System.out.println("NG"); } else { System.out.println("OK"); } } } }