Guest User

CH6 Clock

a guest
Jun 20th, 2011
1,674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.IOException;
  4.  
  5. /*
  6.  * Tuenti Contest
  7.  * Challenge 6 - Clock
  8.  * Author: Pedro Antonio Pardal Jimena
  9.  */
  10.  
  11. public class Clock
  12. {
  13.     private static final int[] Segmentos = new int[] {
  14.         6, 2, 5, 5, 4, 5, 6, 3, 7, 6
  15.     };                                               
  16.    
  17.     private static int getCambios( int digito )
  18.     {
  19.         return Segmentos[digito];
  20.     }
  21.    
  22.     private static int cambiosLed( int hora )
  23.     {
  24.         int horas = ( hora / 3600 ) % 12;
  25.         int minutos = ( hora / 60 ) % 60;
  26.         int segundos = hora % 60;
  27.        
  28.         int cambios = 0;
  29.        
  30.         cambios += getCambios( horas / 10 );
  31.         cambios += getCambios( horas % 10 );
  32.         cambios += getCambios( minutos / 10 );
  33.         cambios += getCambios( minutos % 10 );
  34.         cambios += getCambios( segundos / 10 );
  35.         cambios += getCambios( segundos % 10 );
  36.        
  37.         return cambios;
  38.     }
  39.    
  40.     private static int totalCambiosLed( int s )
  41.     {
  42.         int cambios = 0;
  43.        
  44.         for ( int i = 0; i <= s; i++ )
  45.         {
  46.             cambios += cambiosLed( i );
  47.         }
  48.        
  49.         return cambios;
  50.     }
  51.    
  52.     private static int parseInput( String linea )
  53.     {
  54.         int segundos = Integer.parseInt( linea );
  55.        
  56.         return totalCambiosLed( segundos );
  57.     }
  58.    
  59.     public static void main( String[] args ) throws IOException
  60.     {
  61.         BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
  62.        
  63.         while ( reader.ready() )
  64.         {
  65.             String linea = reader.readLine();
  66.             int result = parseInput( linea );
  67.            
  68.             System.out.println( result );
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment