marcelofoxes

URI 1168 - LED

May 14th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Locale.setDefault(Locale.US);
  7.         Integer[] numberToLedCount = new Integer[10];
  8.        
  9.         // number -> leds
  10.         numberToLedCount[0] = 6;
  11.         numberToLedCount[1] = 2;
  12.         numberToLedCount[2] = 5;
  13.         numberToLedCount[3] = 5;
  14.         numberToLedCount[4] = 4;
  15.         numberToLedCount[5] = 5;
  16.         numberToLedCount[6] = 6;
  17.         numberToLedCount[7] = 3;
  18.         numberToLedCount[8] = 7;
  19.         numberToLedCount[9] = 6;
  20.        
  21.         Scanner scanner = new Scanner(System.in);
  22.         int testCases = scanner.nextInt();
  23.         scanner.nextLine();
  24.        
  25.         for(int caseNo = 0; caseNo < testCases; caseNo++) {
  26.             String numberAsString = scanner.nextLine().trim();
  27.             char[] chars = numberAsString.toCharArray();
  28.             int ledCount = 0;
  29.             for (int i = 0; i < chars.length; i++) {
  30.                 int charAsInt = Character.getNumericValue(chars[i]);
  31.                 ledCount += numberToLedCount[charAsInt];
  32.             }
  33.             System.out.println(ledCount + " leds");
  34.         }
  35.        
  36.         scanner.close();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment