试题编号: | 201909-1 |
---|---|
试题名称: | 小明种苹果 |
时间限制: | 2.0s |
内存限制: | 512.0MB |
问题描述: | |
思路:
创建二维数组记录输入数据,在输入疏果个数时把每行疏果总数记录在另一个数组进行比较
代码:
import java.util.Scanner;
public class Main {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int n = input.nextInt();// 行数(苹果总棵树)
int m = input.nextInt();// 列数(疏果次数)
int last = 0, leave = 0, max = 0, flag = 0;
int data[][] = new int[n][m + 1];
int leaves[] = new int[n];
for (int i = 0; i < n; i++) {
data[i][0] = input.nextInt();
for (int j = 1; j < m + 1; j++) {
data[i][j] = input.nextInt();
leave += data[i][j];
}
leaves[i] = leave;
last += data[i][0] + leave;
leave = 0;
}
for (int i = 0; i < n; i++) {
if (leaves[i] < max) {// 疏果数为负数
max = leaves[i];
flag = i;
}
}
System.out.print(last + " ");
System.out.print(flag + 1 + " ");
System.out.print(Math.abs(max));
}
}
题目链接:http://118.190.20.162/view.page?gpid=T94