• API
• FAQ
• Tools
• Archive
daily pastebin goal
40%
SHARE
TWEET

# Untitled

a guest Jul 9th, 2015 234 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.util.Scanner;
2.
3. public class Main {
4.
5.     public static void main(String[] args) {
6.         Scanner input = new Scanner(System.in);
7.
8.         int[] cont1 = new int[3];
9.         int[] cont2 = new int[3];
10.         int[] cont3 = new int[3];
11.
12.
13.         while (input.hasNext()) {
14.
16.             for (int i = 0; i < 3; i++) {
17.                 cont1[i] = input.nextInt();
18.             }
19.
20.             for (int i = 0; i < 3; i++) {
21.                 cont2[i] = input.nextInt();
22.             }
23.
24.             for (int i = 0; i < 3; i++) {
25.                 cont3[i] = input.nextInt();
26.             }
27.
28.             calculateScores(cont1, cont2, cont3);
29.         }
30.
31.     }
32.
33.     public static void calculateScores(int[] array1, int[] array2, int[] array3) {
34.         int[] cont1Calc = new int[3];
35.         int[] cont2Calc = new int[3];
36.         int[] cont3Calc = new int[3];
37.
38.         //Calculating number of moves needed to put each type of bottle in every position
39.         for(int i = 0; i < 3; i++) {
40.
41.             cont1Calc[i] = array2[i] + array3[i];
42.             cont2Calc[i] = array1[i] + array3[i];
43.             cont3Calc[i] = array1[i] + array2[i];
44.         }
45.
46.
47.         int[] total = new int[6];
48.
49.         //total number of moves needed for all different permutaions
50.         total[0] = cont1Calc[0] + cont2Calc[2] + cont3Calc[1];
51.         total[1] = cont1Calc[0] + cont2Calc[1] + cont3Calc[2];
52.
53.         total[2] = cont1Calc[1] + cont2Calc[0] + cont3Calc[2];
54.         total[3] = cont1Calc[1] + cont2Calc[2] + cont3Calc[0];
55.
56.         total[4] = cont1Calc[2] + cont2Calc[0] + cont3Calc[1];
57.         total[5] = cont1Calc[2] + cont2Calc[1] + cont3Calc[0];
58.
59.         int min = 0;
60.
61.         //finding lowest number of moves
62.         for(int i = 1; i < 6; i++) {
63.             if (total[i] < total[min]) {
64.                 min = i;
65.             }
66.         }
67.
68.         switch (min) {
69.             case 0:
70.                 System.out.println("BCG" + " " +  total[0]);
71.                 break;
72.             case 1:
73.                 System.out.println("BGC" + " " +  total[1]);
74.                 break;
75.             case 2:
76.                 System.out.println("GBC" + " " + total[2]);
77.                 break;
78.             case 3:
79.                 System.out.println("CGB" + " " + total[3]);
80.                 break;
81.             case 4:
82.                 System.out.println("CBG" + " " +   total[4]);
83.                 break;
84.             case 5:
85.                 System.out.println("CGB" + " " + total[5]);
86.                 break;
87.         }
88.     }
89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top