Advertisement
ilianrusev

Cooking Factory

Mar 6th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         String input = scanner.nextLine();
  12.         int maxSum = Integer.MIN_VALUE;
  13.         Double average = 0.00;
  14.         int minSize = 0;
  15.         List<Integer> topBatch = new ArrayList<>();
  16.         System.out.println();
  17.         while(!input.equals("Bake It!")){
  18.             List<Integer> batch = Arrays.stream(input.split("#"))
  19.                     .map(Integer::parseInt)
  20.                     .collect(Collectors.toList());
  21.             int sum = 0;
  22.             for (int i = 0; i <batch.size(); i++) {
  23.  
  24.                 sum += batch.get(i);
  25.  
  26.             }
  27.  
  28.             Double greaterAverage = (double)sum / batch.size();
  29.             int size=batch.size();
  30.  
  31.  
  32.  
  33.             if (maxSum < sum){
  34.  
  35.                 maxSum = sum;
  36.                 average=greaterAverage;
  37.                 minSize=size;
  38.  
  39.                 topBatch = new ArrayList<>(batch);
  40.             }else if (maxSum == sum){
  41.  
  42.                 if (average < greaterAverage){
  43.                     average = greaterAverage;
  44.                     minSize=size;
  45.  
  46.                     topBatch = new ArrayList<>(batch);
  47.                 }else if (greaterAverage.equals(average)){
  48.  
  49.                     if (minSize > size ){
  50.                         minSize=size;
  51.  
  52.                         topBatch = new ArrayList<>(batch);
  53.                     }
  54.  
  55.  
  56.                 }
  57.             }
  58.  
  59.  
  60.             input = scanner.nextLine();
  61.         }
  62.         System.out.printf("Best Batch quality: %d\n",maxSum);
  63.         for(int i=0; i < topBatch.size(); i++){
  64.             System.out.print(topBatch.get(i)+" ");
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement