题解 | #密码验证合格程序#

密码验证合格程序

http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            String str = scan.nextLine();
            int [] sum = new int [4];
            char [] arrays = str.toCharArray();
            for (int i = 0 ; i < arrays.length; i++) {
                if (arrays.length < 8) {
                    break;
                }
                if (arrays[i] >= '0' && arrays[i] <= '9') {
                    sum[0] = 1;
                }
                if (arrays[i] >= 'a' && arrays[i] <= 'z') {
                    sum[1] = 1;
                }
                if (arrays[i] >= 'A' && arrays[i] <= 'Z') {
                    sum[2] = 1;
                }
                if (arrays[i] == '@' || arrays[i] == '#' ||
                        arrays[i] == '^' || arrays[i] == '&' || arrays[i] == '*' || arrays[i] == '$' ||
                        arrays[i] == '%') {
                    sum[3] = 1;
                }
            }
            int sum2 = 0;
            for (int i = 0; i < sum.length; i++) {
                sum2 = sum2 + sum[i];
            }
            if (sum2 < 3) {
                System.out.println("NG");
            } else {
                boolean flag = true;
                for (int i = 0; i < arrays.length; i++) {
                    String s = String.valueOf(arrays[i]);
                    loop1:
                    for (int j = i - 1; j >= i / 2; j--) {
                        s = arrays[j] + s;
                        String s2 = "";
                        for (int k = 0 ; k < j; k++) {
                            s2 = s2 + arrays[k];
                        }
                        if (s2.contains(s) && s.length() > 2) {
                            flag = false;
                            break loop1;
                        }
                    }
                }
                if (flag) {
                    System.out.println("OK");
                } else {
                    System.out.println("NG");
                }
            }
        }
    }
}

全部评论

相关推荐

专心打鱼:互联网搬运工,贴子都要偷
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务