201909-1 小明种苹果

2020-01-07  本文已影响0人  月影追猎者

试题编号:201909-1
试题名称:小明种苹果
时间限制:2.0s
内存限制:512.0MB

201909-1 小明种苹果
Java实现
import java.util.Scanner;

public class Apple {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] str = scanner.nextLine().split(" ");
        int treeNum = Integer.parseInt(str[0]);
        int thinNum = Integer.parseInt(str[1]);
        int[][] data = new int[treeNum][thinNum + 1];
        int[] thinSum = new int[treeNum];
        int thinMax = 0;
        int sum = 0;
        int num = 1;
        for (int i = 0; i < treeNum; i++) {
            String[] tree = scanner.nextLine().split(" ");
            for (int j = 0; j < thinNum + 1; j++) {
                data[i][j] = Integer.parseInt(tree[j]);
                sum += data[i][j];
                if (j != 0) {
                    thinSum[i] -= data[i][j];
                }
            }
            if (thinMax < thinSum[i]) {
                thinMax = thinSum[i];
                num = i + 1;
            }
        }
        System.out.println(sum + " " + num + " " + thinSum[num - 1]);
    }
}
上一篇下一篇

猜你喜欢

热点阅读