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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String str = sc.nextLine();
            int len = str.length();            
            int[] a = new int[4];
            int cnt = 0, num = 0;

            for (int i = 0; i < len; ++i) {
                if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
                    a[0] = 1;
                else if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
                    a[1] = 1;
                else if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
                    a[2] = 1;
                else
                    a[3] = 1;
            }

            for (int i = 0; i < 4; i++) {
                if (a[i] == 1)
                    cnt++;
            }

            for (int i = 0; i <= len - 6; i++) {
                for (int j = i + 3; j <= len - 3; j++) {
                    if ((str.charAt(i) == str.charAt(j)) && (str.charAt(i + 1) == str.charAt(j + 1)) && (str.charAt(i + 2) == str.charAt(j + 2)))
                        num++;
                    if (num != 0)
                        break;
                }
                if (num != 0)
                    break;
            }
            if ((len >= 9) && (cnt >= 3) && (num == 0))
                System.out.println("OK");
            else 
                System.out.println("NG");
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务