I'm trying to solve URI problem 1168. However, I can not get the number of leds needed to mount a number. Specifically, my valorLed
variable is always resulting in zero. Can you help me?
Problem: link
My code:
import java.util.Scanner;
public class Main {
public static void main (String []args){
Scanner sc = new Scanner(System.in);
String n = sc.next();
String v = sc.next();
/* matriz faz a correspondencia entre um algarismo e a
quantidade de led necessaria p/ monta-lo */
char [][] matriz = {{0,6}, {1,2}, {2,5}, {3,5}, {4,4}, {5,5}, {6,6}, {7,3}, {8,7}, {9,6}};
char[] listV = v.toCharArray();
//valorLed eh a variavel responsavel por armazenar o numero de leds necessarios
int valorLed = 0;
for(int linha = 0; linha < 9; linha++){
for(int x = 0; x < listV.length; x++ ){
if(matriz[linha][0] == listV[x]){
valorLed += (int) matriz[linha][1];
}
}
}
System.out.print(valorLed);
}
}
Thank you in advance