Advertisement
Guest User

102

a guest
Jan 3rd, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.OutputStreamWriter;
  3. import java.io.PrintWriter;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.    
  8.     public static void main(String[] args) {
  9.         Scanner in = new Scanner(System.in);
  10.         PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  11.        
  12.         boolean[][] combs =
  13.         //  0       1       2       3       4       5       6       7       8
  14. /*BCG*/ { { false , true  , true  , true  , true  , false , true  , false , true  } ,
  15. /*BGC*/   { false , true  , true  , true  , false , true  , true  , true  , false } ,
  16. /*CBG*/   { true  , true  , false , false , true  , true  , true  , false , true  } ,
  17. /*CGB*/   { true  , true  , false , true  , false , true  , false , true  , true  } ,
  18. /*GBC*/   { true  , false , true  , false , true  , true  , true  , true  , false } ,
  19. /*GCB*/   { true  , false , true  , true  , true  , false , false , true  , true  } };
  20.        
  21.         String[] labels = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
  22.        
  23.         while (in.hasNextInt()) {
  24.             int[] bottles = new int[9];
  25.             for (int i = 0; i < 9; i++)
  26.                 bottles[i] = in.nextInt();
  27.  
  28.             int bestid = 0;
  29.             int bestsum = 0;
  30.             for (int j = 0; j < 9; j++) {
  31.                 if (combs[0][j])
  32.                     bestsum += bottles[j];
  33.             }
  34.                
  35.             for (int i = 1; i < 6; i++) {
  36.                 int sum = 0;
  37.                 for (int j = 0; j < 9; j++) {
  38.                     if (combs[i][j])
  39.                         sum += bottles[j];
  40.                 }
  41.                 if (sum < bestsum) {
  42.                     bestid = i;
  43.                     bestsum = sum;
  44.                 }
  45.             }
  46.            
  47.             System.out.printf("%s %d%n", labels[bestid], bestsum);
  48.         }
  49.         in.close();
  50.         out.close();
  51.     }
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement