试题编号:201909-1
试题名称:小明种苹果
时间限制:2.0s
内存限制:512.0MB
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]);
}
}
网友评论