Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
- boolean[][] combs =
- // 0 1 2 3 4 5 6 7 8
- /*BCG*/ { { false , true , true , true , true , false , true , false , true } ,
- /*BGC*/ { false , true , true , true , false , true , true , true , false } ,
- /*CBG*/ { true , true , false , false , true , true , true , false , true } ,
- /*CGB*/ { true , true , false , true , false , true , false , true , true } ,
- /*GBC*/ { true , false , true , false , true , true , true , true , false } ,
- /*GCB*/ { true , false , true , true , true , false , false , true , true } };
- String[] labels = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
- while (in.hasNextInt()) {
- int[] bottles = new int[9];
- for (int i = 0; i < 9; i++)
- bottles[i] = in.nextInt();
- int bestid = 0;
- int bestsum = 0;
- for (int j = 0; j < 9; j++) {
- if (combs[0][j])
- bestsum += bottles[j];
- }
- for (int i = 1; i < 6; i++) {
- int sum = 0;
- for (int j = 0; j < 9; j++) {
- if (combs[i][j])
- sum += bottles[j];
- }
- if (sum < bestsum) {
- bestid = i;
- bestsum = sum;
- }
- }
- System.out.printf("%s %d%n", labels[bestid], bestsum);
- }
- in.close();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement