CCF 201909-2 小明种苹果(续)(100分)Java

CCF 201909-2 小明种苹果(续)(100分)Java

 

 CCF 201909-2 小明种苹果(续)(100分)Java

 

 CCF 201909-2 小明种苹果(续)(100分)Java

 

 认证时候提交的代码,因此没有注释

import java.util.*;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }
    
    public void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] count = new int[n][1001];
        int size[] = new int[n];
        for(int i = 0; i < n; i++) {
            int m = sc.nextInt();
            size[i] = m;
            for(int j = 0; j < m; j++) {
                count[i][j] = sc.nextInt();
            }
        }
        
        int[] sum = new int[n];
        int[] del = new int[n];
        int allSum = 0;
        for(int i = 0; i < n; i++) {
            sum[i] = count[i][0];
            for(int j = 1; j < size[i]; j++) {
                if(count[i][j] > 0) {
                    if(sum[i] != count[i][j]) {
                        del[i] = 1;
                    }
                    sum[i] = count[i][j];
                }else {
                    sum[i] += count[i][j];
                }
                
            }
            allSum += sum[i];
        }
        int delCount = 0;
        int group = 0;
        for(int i = 0; i < n; i++) {
            if(del[i] != 0) {
                delCount ++;
                if(i == 0) {
                    if(del[n-1] != 0 && del[i+1] != 0) {
                        group ++;
                    }
                }else if(i == n-1) {
                    if(del[i-1] != 0 && del[0] != 0) {
                        group ++;
                    }
                }else {
                    if(del[i-1] != 0 && del[i+1] != 0) {
                        group ++;
                    }
                }
            }
        }
        System.out.println(allSum+" "+delCount+" "+group);
    }
}

CCF 201909-2 小明种苹果(续)(100分)Java

上一篇:通用 mapper的简单使用


下一篇:CCF 201909-1 小明种苹果(100分)Java