Guest User

Untitled

a guest
Mar 2nd, 2019
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class kur {
  8.     public static void main(String[] args) {
  9.  
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         int[] bestBatch = new int[0];
  13.         double sumBestBatch = Integer.MIN_VALUE;
  14.         double bestQuality = Integer.MIN_VALUE;
  15.         String input = scanner.nextLine();
  16.  
  17.         while (!"Bake It!".equals(input)) {
  18.  
  19.             int[] batches = Arrays.stream(input.split("#")).mapToInt(Integer::parseInt).toArray();
  20.             double currentBatch = 0;
  21.  
  22.             for (int i = 0; i < 10; i++) {
  23.                 if (i > batches.length - 1) {
  24.                     break;
  25.                 }
  26.                 if (batches[i] >= - 100 && batches[i] <= 100) {
  27.                     currentBatch += batches[i];
  28.                 }
  29.             }
  30.             double averageQuality = currentBatch / batches.length;
  31.  
  32.             if (currentBatch >= sumBestBatch && averageQuality > bestQuality) {
  33.                 sumBestBatch = currentBatch;
  34.                 bestQuality = averageQuality;
  35.                 bestBatch = batches;
  36.             }else if (currentBatch == sumBestBatch && averageQuality == bestQuality){
  37.                 if (bestBatch.length > batches.length) {
  38.                     bestBatch = batches;
  39.                 }
  40.             }
  41.             input = scanner.nextLine();
  42.         }
  43.         String print = "";
  44.  
  45.         for (int i = 0; i < bestBatch.length; i++) {
  46.             print += bestBatch[i] + " ";
  47.         }
  48.         if (sumBestBatch != Integer.MIN_VALUE) {
  49.             System.out.printf("Best Batch quality: %.0f\n%s", sumBestBatch, print);
  50.         }
  51.     }
  52. }
RAW Paste Data