Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package theClock;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class TheClock {
- private Integer cuantosEn59[];
- private Integer numLed[];
- private Integer totalDisplayados[];
- private int[] tiempo; // Variable para almacenar el tiempo
- private int cerosDecenas;
- private int numledDecenas;
- public TheClock(int segundos) {
- tiempo = new int[3];
- numLed = new Integer[10];
- numLed[0] = 1;
- numLed[1] = 0;
- numLed[2] = 4;
- numLed[3] = 1;
- numLed[4] = 1;
- numLed[5] = 2;
- numLed[6] = 1;
- numLed[7] = 1;
- numLed[8] = 4;
- numLed[9] = 0;
- numledDecenas = 2;
- cuantosEn59 = new Integer[10];
- for (int i = 0; i < 10; i++) {
- cuantosEn59[i] = cuantosAparecen(i, 59);
- }
- intToTime(segundos);
- totalDisplayados = new Integer[9 + 1];
- for (int i = 0; i < 10; i++) {
- int auxDisplay;
- auxDisplay = contarDigitos(i, tiempo, 60, cuantosEn59[i]);
- totalDisplayados[i] = auxDisplay;
- }
- totalDisplayados[0] -= 3;
- cerosDecenas = tiempo[0] + tiempo[0] * 59 + tiempo[1];
- }
- /**
- * Obtiene el total de led's que hemos displayado
- *
- * @return el n�mero de led's displayados
- */
- public int getTotalLedDisplayados() {
- int devolver = 0;
- for (int i = 0; i < 10; i++) {
- devolver += totalDisplayados[i] * numLed[i];
- }
- devolver += cerosDecenas * numledDecenas;
- return devolver + 36;
- }
- private void intToTime(int segundos) {
- tiempo[0] = segundos / 3600;
- segundos %= 3600;
- tiempo[1] = segundos / 60;
- segundos %= 60;
- tiempo[2] = segundos;
- }
- public static int contarDigitos(int value, int array[], int base,
- int numAparicionesBase) {
- int devolver = 0;
- for (int i = 0; i < array.length; i++) {
- devolver += (antes(array, i, base)) * numAparicionesBase
- + cuantosAparecen(value, array[i]);
- }
- return devolver;
- }
- public static int antes(int array[], int indice, int base) {
- int resultado = 0;
- for (int i = 0; i < indice; i++) {
- resultado += array[i] * Math.pow(base, indice - i - 1);
- }
- return resultado;
- }
- public static int cuantasCifras(int numero) {
- int aux = 0;
- while (numero > 0) {
- numero /= 10;
- aux++;
- }
- return aux;
- }
- public static int cuantosAparecen(int buscado, int valor) {
- if (buscado == 0) {
- return valor / 10 + 1;
- }
- int delante;
- int actual;
- int numCifras;
- int devolver = 0;
- numCifras = cuantasCifras(valor);
- for (int i = numCifras - 1; i >= 0; i--) {
- int aux = (int) Math.pow(10, i);
- int aparicionesPosicionActual = 0;
- delante = valor / aux;
- actual = delante % 10;
- delante /= 10;
- if (actual >= buscado) {
- aparicionesPosicionActual = (delante + 1);
- } else {
- aparicionesPosicionActual = delante;
- }
- devolver += aparicionesPosicionActual;
- }
- return devolver;
- }
- public static void main(String[] args) {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- try {
- while (br.ready()) {
- String linea = br.readLine();
- TheClock theClock = new TheClock(Integer.parseInt(linea));
- System.out.println(theClock.getTotalLedDisplayados());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement