Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int[] cont1 = new int[3];
- int[] cont2 = new int[3];
- int[] cont3 = new int[3];
- while (input.hasNext()) {
- //Reading inputs
- for (int i = 0; i < 3; i++) {
- cont1[i] = input.nextInt();
- }
- for (int i = 0; i < 3; i++) {
- cont2[i] = input.nextInt();
- }
- for (int i = 0; i < 3; i++) {
- cont3[i] = input.nextInt();
- }
- calculateScores(cont1, cont2, cont3);
- }
- }
- public static void calculateScores(int[] array1, int[] array2, int[] array3) {
- int[] cont1Calc = new int[3];
- int[] cont2Calc = new int[3];
- int[] cont3Calc = new int[3];
- //Calculating number of moves needed to put each type of bottle in every position
- for(int i = 0; i < 3; i++) {
- cont1Calc[i] = array2[i] + array3[i];
- cont2Calc[i] = array1[i] + array3[i];
- cont3Calc[i] = array1[i] + array2[i];
- }
- int[] total = new int[6];
- //total number of moves needed for all different permutaions
- total[0] = cont1Calc[0] + cont2Calc[2] + cont3Calc[1];
- total[1] = cont1Calc[0] + cont2Calc[1] + cont3Calc[2];
- total[2] = cont1Calc[1] + cont2Calc[0] + cont3Calc[2];
- total[3] = cont1Calc[1] + cont2Calc[2] + cont3Calc[0];
- total[4] = cont1Calc[2] + cont2Calc[0] + cont3Calc[1];
- total[5] = cont1Calc[2] + cont2Calc[1] + cont3Calc[0];
- int min = 0;
- //finding lowest number of moves
- for(int i = 1; i < 6; i++) {
- if (total[i] < total[min]) {
- min = i;
- }
- }
- switch (min) {
- case 0:
- System.out.println("BCG" + " " + total[0]);
- break;
- case 1:
- System.out.println("BGC" + " " + total[1]);
- break;
- case 2:
- System.out.println("GBC" + " " + total[2]);
- break;
- case 3:
- System.out.println("CGB" + " " + total[3]);
- break;
- case 4:
- System.out.println("CBG" + " " + total[4]);
- break;
- case 5:
- System.out.println("CGB" + " " + total[5]);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement