Kabbage 之前做爆的OA(字符串处理)

之前的kabbage OA自己做爆了,现在换了邮箱,说是下面俩天发coding link给我。
我回忆一下之前那道题,估计还是一样的题目,因为之前同学实习,也是做的这个题目,那个时候还一起做的。
输入一个字符串,判断是否合法 包含三种command
-help 后面不用接啥
-count 后面接10-100的数字
-string 具体要求不记得了

是一道String pattern的题目,不难 ,做的时候慌了,也就挂了。

public class Kabbage {
    public static void main(String[] args) {
        System.out.println(isValid("-help -name boqrb -count 92 -help -name yuhao"));
    }

    public static boolean isValid(String s) {
        if (s.length() == 0 || s == null) return false;
        String [] check = s.split("\\s+");
        int len = check.length;
        /**
         * System.out.println("len =" +len);
         * for(int i = 0; i < len ;i++) {
         *    System.out.println(check[i]);
         * }
         */
        for (int i = 0;i < len;i++) {
            if (check[i].equals("-help")) {
                if(i == len - 1) {
                    return true;
                } else if (i == len - 2) {
                    return false;
                } else {
                    continue;
                }
            } else if (check[i].equals("-count")) {
                if(i == len - 1) {
                    return false;
                } else if (i == len - 2) {
                    return Integer.parseInt(check[i+1])<=100 && Integer.parseInt(check[i+1])>=10;
                } else {
                    int tempcheck = Integer.parseInt(check[i+1]);
                    if (tempcheck <= 100 && tempcheck >= 10) {
                        i = i + 1;
                    } else {
                        return false;
                    }
                }
            } else if (check[i].equals("-name")) {
                if(i == len - 1) {
                    return false;
                } else if (i == len - 2) {
                    return isValidName(check[i+1]);
                } else {
                    if (isValidName(check[i+1])) {
                        i = i + 1;
                    } else {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }
        return true;
    }

    private static boolean isValidName(String check) {
        char[] chs = check.toCharArray();
        for (int i = 0; i < chs.length;i++) {
            if ((chs[i]>='a' &&  chs[i] <='z') || (chs[i]>='A' &&  chs[i] <='Z')) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }

}

下班回家 做一做 我也不太记得全部了 确实不难

噗 他们家HR说 team里的人看了觉得不是很符合背景 又不给OA了

这世道怎么了⊙_⊙