Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DemoMidExam_02032018;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class _03_CookingFactory {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> best = Arrays.stream(scanner.nextLine()
- .split("#"))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- int sumBest = 0;
- for (int i = 0; i < best.size(); i++) {
- sumBest += best.get(i);
- }
- int bestQ = sumBest;
- int bestAvr = bestQ / best.size();
- String input = "";
- while (!(input = scanner.nextLine()).equals("Bake It!")) {
- //Current batch:
- List<Integer> current = Arrays.stream(input
- .split("#"))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- int sum = 0;
- for (int i = 0; i < current.size(); i++) {
- sum += current.get(i);
- }
- int currentQ = sum;
- int currentAvr = currentQ / current.size();
- if (bestQ < currentQ){
- best = current;
- bestQ = currentQ;
- bestAvr = currentAvr;
- } else if (bestQ == currentQ){
- if (bestAvr < currentAvr){
- best = current;
- bestQ = currentQ;
- bestAvr = currentAvr;
- } else if (best.size() > current.size()){
- best = current;
- bestQ = currentQ;
- bestAvr = currentAvr;
- }
- }
- }
- System.out.println("Best Batch quality: " + bestQ);
- System.out.println(best.toString().replaceAll("[\\[\\],]", ""));
- }
- }
- //https://judge.softuni.bg/Contests/Practice/Index/1579#2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement