Advertisement
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;
- import java.util.stream.Collectors;
- public class kur {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] bestBatch = new int[0];
- double sumBestBatch = Integer.MIN_VALUE;
- double bestQuality = Integer.MIN_VALUE;
- String input = scanner.nextLine();
- while (!"Bake It!".equals(input)) {
- int[] batches = Arrays.stream(input.split("#")).mapToInt(Integer::parseInt).toArray();
- double currentBatch = 0;
- for (int i = 0; i < 10; i++) {
- if (i > batches.length - 1) {
- break;
- }
- if (batches[i] >= - 100 && batches[i] <= 100) {
- currentBatch += batches[i];
- }
- }
- double averageQuality = currentBatch / batches.length;
- if (currentBatch >= sumBestBatch && averageQuality > bestQuality) {
- sumBestBatch = currentBatch;
- bestQuality = averageQuality;
- bestBatch = batches;
- }else if (currentBatch == sumBestBatch && averageQuality == bestQuality){
- if (bestBatch.length > batches.length) {
- bestBatch = batches;
- }
- }
- input = scanner.nextLine();
- }
- String print = "";
- for (int i = 0; i < bestBatch.length; i++) {
- print += bestBatch[i] + " ";
- }
- if (sumBestBatch != Integer.MIN_VALUE) {
- System.out.printf("Best Batch quality: %.0f\n%s", sumBestBatch, print);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement