Advertisement
bkit4s0

[codechef] CANDLE

Apr 14th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class type {
  6.     public static void main(String args[]) throws NumberFormatException,
  7.             IOException {
  8.  
  9.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  10.         int t = Integer.parseInt(in.readLine());
  11.         while (t-- > 0) {
  12.             String[] candle = new String[10];
  13.             candle = in.readLine().split(" ");
  14.             int[] a = new int[10];
  15.             for (int i = 0; i < 10; i++) {
  16.                 a[i] = Integer.parseInt(candle[i]);
  17.             }
  18.             boolean boo = false;
  19.             for (int i = 1; i < 1000 && !boo; i++) {
  20.                 int tmp = i;
  21.                 /*
  22.                  * how to solve problem when we use one candle -> use one array
  23.                  * to update ???
  24.                  */
  25.                 int[] b = new int[10];
  26.                 for (int j = 0; j < 10; j++) {
  27.                     b[j] = a[j];
  28.                 }
  29.                 /*solve problem*/
  30.                 while (tmp > 0) {
  31.                     if (b[tmp % 10] < 1) {
  32.                         System.out.println(i);
  33.                         boo = true;
  34.                         break;
  35.                     } else {
  36.                         /* use one candle */
  37.                         b[tmp % 10]--;
  38.                     }
  39.                     tmp = tmp / 10;
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement