201909-1 小明种苹果 Java

201909-1  小明种苹果 Java

思路:
保存掉落的苹果总数,和树是第几棵即可

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
        String[] line = buff.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int m = Integer.parseInt(line[1]);
        
        int sum = 0;//总数
        int maxCnt = 1;//最大掉落数的下标
        int maxSum = 0;//最大掉落数
        
        for ( int i = 1; i <= n; i++ ) {
            line = buff.readLine().split(" ");
            int temp = Integer.parseInt(line[0]);//当前树的苹果数
            int downNum = 0;//掉落的数量
            for ( int j = 1; j <= m; j++ ) {
                downNum += Integer.parseInt(line[j]);
            }
            downNum = Math.abs(downNum);
            if ( downNum > maxSum ) {
                maxSum = downNum;
                maxCnt = i;
            }
            
            sum += temp-downNum;
        }
        System.out.println(sum+" "+maxCnt+" "+maxSum);
    }
}

201909-1 小明种苹果 Java

上一篇:解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'


下一篇:模仿虎牙App 导航栏切换