Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- /*
- * Tuenti Contest
- * Challenge 13 - Other Clock
- * Author: Pedro Antonio Pardal Jimena
- * Email: pardal@alu.uma.es
- */
- public class OtherClock
- {
- private static final int[] CambiosDiez = new int[] {
- 1, 0, 4, 1, 1, 2, 1, 1, 4, 0
- };
- private static final int[] CambiosSeis = new int[] {
- 2, 0, 4, 1, 1, 2
- };
- private static final int[] CambiosUno = new int[] {
- 4, 0
- };
- private static int totalCambiosLed( int s )
- {
- int cambios = 36; // inicialmente...
- int horaAntigua = 0, minutosAntiguos = 0, segundosAntiguos = 0;
- for ( int i = 0; i <= s; i++ )
- {
- int horas = ( i / 3600 ) % 12;
- int minutos = ( i / 60 ) % 60;
- int segundos = i % 60;
- if ( horas / 10 != horaAntigua / 10)
- cambios += CambiosUno[horas / 10];
- if ( horas % 10 != horaAntigua % 10)
- cambios += CambiosDiez[horas % 10];
- if ( minutos / 10 != minutosAntiguos / 10 )
- cambios += CambiosSeis[minutos / 10];
- if ( minutos % 10 != minutosAntiguos % 10 )
- cambios += CambiosDiez[minutos % 10];
- if ( segundos / 10 != segundosAntiguos / 10 )
- cambios += CambiosSeis[segundos / 10];
- if ( segundos % 10 != segundosAntiguos % 10 )
- cambios += CambiosDiez[segundos % 10];
- horaAntigua = horas;
- minutosAntiguos = minutos;
- segundosAntiguos = segundos;
- }
- return cambios;
- }
- private static int parseInput( String linea )
- {
- int segundos = Integer.parseInt( linea );
- return totalCambiosLed( segundos );
- }
- public static void main( String[] args ) throws IOException
- {
- BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
- while ( reader.ready() )
- {
- String linea = reader.readLine();
- int result = parseInput( linea );
- System.out.println( result );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement