Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class cookingFactory {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String[] input = scan.nextLine().split("#");
- double bestAvrg = 0;
- int bestSum = 0;
- int lowestIndex = Integer.MAX_VALUE;
- List<Integer> bestBatch = new ArrayList<>();
- while (!input[0].equals("Bake It!")) {
- Integer[] value = new Integer[input.length];
- int index = input.length;
- int sum = 0;
- for (int i = 0; i < index; i++) {
- value[i] = Integer.parseInt(input[i]);
- sum += value[i];
- }
- if (value.length < lowestIndex) {
- lowestIndex = value.length;
- }
- double avrg = sum * 1.0 / index;
- if (sum > bestSum) {
- bestAvrg = avrg;
- bestSum = sum;
- bestBatch = Arrays.asList(value);
- } else if (sum >= bestSum && avrg > bestAvrg) {
- bestAvrg = avrg;
- bestSum = sum;
- bestBatch = Arrays.asList(value);
- } else if (sum == bestSum && avrg == bestAvrg && lowestIndex < value.length) {
- bestAvrg = avrg;
- bestSum = sum;
- bestBatch = Arrays.asList(value);
- }
- input = scan.nextLine().split("#");
- }
- System.out.printf("Best Batch quality: %d%n", bestSum);
- for (Integer bestBatch1 : bestBatch) {
- System.out.print(bestBatch1 + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment