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 6 - Clock
- * Author: Pedro Antonio Pardal Jimena
- * Email: pardal@alu.uma.es
- */
- public class Clock
- {
- private static final int[] Segmentos = new int[] {
- 6, 2, 5, 5, 4, 5, 6, 3, 7, 6
- };
- private static int getCambios( int digito )
- {
- return Segmentos[digito];
- }
- private static int cambiosLed( int hora )
- {
- int horas = ( hora / 3600 ) % 12;
- int minutos = ( hora / 60 ) % 60;
- int segundos = hora % 60;
- int cambios = 0;
- cambios += getCambios( horas / 10 );
- cambios += getCambios( horas % 10 );
- cambios += getCambios( minutos / 10 );
- cambios += getCambios( minutos % 10 );
- cambios += getCambios( segundos / 10 );
- cambios += getCambios( segundos % 10 );
- return cambios;
- }
- private static int totalCambiosLed( int s )
- {
- int cambios = 0;
- for ( int i = 0; i <= s; i++ )
- {
- cambios += cambiosLed( i );
- }
- 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 );
- }
- }
- }
RAW Paste Data