Guest User

CH13 OtherClock

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