美文网首页
201909-1 小明种苹果

201909-1 小明种苹果

作者: 月影追猎者 | 来源:发表于2020-01-07 16:01 被阅读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]);
        }
    }
    

    相关文章

      网友评论

          本文标题:201909-1 小明种苹果

          本文链接:https://www.haomeiwen.com/subject/ilaractx.html