Advertisement
Guest User

CH13 OtherClock

a guest
Jun 20th, 2011
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 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 13 - Other Clock
  8.  * Author: Pedro Antonio Pardal Jimena
  9.  * Email: pardal@alu.uma.es
  10.  */
  11.  
  12. public class OtherClock
  13. {
  14.     private static final int[] CambiosDiez = new int[] {
  15.         1, 0, 4, 1, 1, 2, 1, 1, 4, 0
  16.     };
  17.    
  18.     private static final int[] CambiosSeis = new int[] {
  19.         2, 0, 4, 1, 1, 2
  20.     };
  21.    
  22.     private static final int[] CambiosUno = new int[] {
  23.         4, 0
  24.     };
  25.    
  26.     private static int totalCambiosLed( int s )
  27.     {
  28.         int cambios = 36; // inicialmente...
  29.        
  30.         int horaAntigua = 0, minutosAntiguos = 0, segundosAntiguos = 0;
  31.        
  32.         for ( int i = 0; i <= s; i++ )
  33.         {
  34.             int horas = ( i / 3600 ) % 12;
  35.             int minutos = ( i / 60 ) % 60;
  36.             int segundos = i % 60;
  37.            
  38.             if ( horas / 10 != horaAntigua / 10)
  39.                 cambios += CambiosUno[horas / 10];
  40.            
  41.             if ( horas % 10 != horaAntigua % 10)
  42.                 cambios += CambiosDiez[horas % 10];
  43.            
  44.             if ( minutos / 10 != minutosAntiguos / 10 )
  45.                 cambios += CambiosSeis[minutos / 10];
  46.            
  47.             if ( minutos % 10 != minutosAntiguos % 10 )
  48.                 cambios += CambiosDiez[minutos % 10];
  49.            
  50.             if ( segundos / 10 != segundosAntiguos / 10 )
  51.                 cambios += CambiosSeis[segundos / 10];
  52.            
  53.             if ( segundos % 10 != segundosAntiguos % 10 )
  54.                 cambios += CambiosDiez[segundos % 10];
  55.            
  56.             horaAntigua = horas;
  57.             minutosAntiguos = minutos;
  58.             segundosAntiguos = segundos;
  59.         }
  60.        
  61.         return cambios;
  62.     }
  63.    
  64.     private static int parseInput( String linea )
  65.     {
  66.         int segundos = Integer.parseInt( linea );
  67.        
  68.         return totalCambiosLed( segundos );
  69.     }
  70.    
  71.     public static void main( String[] args ) throws IOException
  72.     {
  73.         BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
  74.        
  75.         while ( reader.ready() )
  76.         {
  77.             String linea = reader.readLine();
  78.             int result = parseInput( linea );
  79.            
  80.             System.out.println( result );
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement