CCF201909-2小明种苹果(续)java

题目

CCF201909-2小明种苹果(续)java_第1张图片
CCF201909-2小明种苹果(续)java_第2张图片

代码

public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int trees = scanner.nextInt();
        scanner.nextLine();
        int T = 0;
        int D = 0;
        int E = 0;
        int[] aa = new int[trees + 2];
        for (int i = 0; i < trees; i++) {
            String arg = scanner.nextLine();
            String[] cc = arg.trim().split(" ");
            int intCount = Integer.parseInt(cc[0]);
            int appleCount = Integer.parseInt(cc[1]);
            boolean hasDrop = false;
            for (int j = 2; j < intCount + 1; j++) {
                if (Integer.parseInt(cc[j]) > 0) {
                    if (appleCount > Integer.parseInt(cc[j]) && !hasDrop) {
                        hasDrop = true;
                        D++;
                        aa[i] = 1;
                    }
                    appleCount = Integer.parseInt(cc[j]);
                } else {
                    appleCount += Integer.parseInt(cc[j]);
                }
            }
            T += appleCount;
        }
        aa[trees] = aa[0];
        aa[trees + 1] = aa[1];
        for (int i = 1; i < trees + 1; i++) {
            if (aa[i - 1] == 1 && aa[i] == 1 && aa[i + 1] == 1) {
                E++;
            }
        }
        String result = T + " " + D + " " + E;
        System.out.println(result);
    }

你可能感兴趣的:(CCF201909-2小明种苹果(续)java)