la-ma-rin

cookingFactory

Mar 3rd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class cookingFactory {
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         String[] input = scan.nextLine().split("#");
  11.  
  12.         double bestAvrg = 0;
  13.         int bestSum = 0;
  14.  
  15.         int lowestIndex = Integer.MAX_VALUE;
  16.  
  17.         List<Integer> bestBatch = new ArrayList<>();
  18.  
  19.         while (!input[0].equals("Bake It!")) {
  20.  
  21.             Integer[] value = new Integer[input.length];
  22.  
  23.             int index = input.length;
  24.  
  25.             int sum = 0;
  26.  
  27.             for (int i = 0; i < index; i++) {
  28.                 value[i] = Integer.parseInt(input[i]);
  29.                 sum += value[i];
  30.             }
  31.  
  32.             if (value.length < lowestIndex) {
  33.                 lowestIndex = value.length;
  34.             }
  35.  
  36.             double avrg = sum * 1.0 / index;
  37.  
  38.             if (sum > bestSum) {
  39.                 bestAvrg = avrg;
  40.                 bestSum = sum;
  41.                 bestBatch = Arrays.asList(value);
  42.             } else if (sum >= bestSum && avrg > bestAvrg) {
  43.                 bestAvrg = avrg;
  44.                 bestSum = sum;
  45.                 bestBatch = Arrays.asList(value);
  46.             } else if (sum == bestSum && avrg == bestAvrg && lowestIndex < value.length) {
  47.                 bestAvrg = avrg;
  48.                 bestSum = sum;
  49.                 bestBatch = Arrays.asList(value);
  50.             }
  51.  
  52.             input = scan.nextLine().split("#");
  53.         }
  54.  
  55.         System.out.printf("Best Batch quality: %d%n", bestSum);
  56.         for (Integer bestBatch1 : bestBatch) {
  57.             System.out.print(bestBatch1 + " ");
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment