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");
        }
    }
}

全部评论

相关推荐

牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务