/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.util.Random;
import java.util.Arrays;
interface Constantes{
final static int EQUIPOS = 8, POSTAS = 4;
}
class CarreraApp implements Constantes{
public static void main(String[] args){
System.out.println("\tBienvenidos a la carrera de " + POSTAS + " postas");
Equipo[] equipos = new Equipo[EQUIPOS];
for(int i=0; i<EQUIPOS; i++)
equipos[i] = new Equipo(i);
for(Equipo eq: equipos)
eq.correr();
Arrays.sort(equipos);
// Reporte de la carrera
System.out.println("Equipo Tiempos ordenados por TOTAL");
for (int i=0; i<POSTAS;)
System.out.print("\tPosta " + ++i);
System.out.println("\tTOTAL");
for(Equipo eq: equipos){
System.out.printf(" %2d ", eq.numero);
for (int i=0; i<POSTAS; i++)
System.out.printf(" %2d",eq.tiempoCorredor[i]);
System.out.printf(" %2d\n", eq.tiempo);
}
// Reporte de ganadores
int primeros = 0, valor = equipos[0].tiempo;
for(Equipo eq: equipos)
if(eq.tiempo == valor)
primeros++;
else
break;
if(primeros==1)
System.out.println("Felicitaciones al equipo ganador de la carrera: " + equipos[0].numero);
else {
System.out.print("Felicitaciones a los equipos ganadores de la carrera: " + equipos[0].numero);
for(int p=1; p<primeros; p++)
System.out.print(", " + equipos[p].numero);
System.out.println();
}
}
}
class Equipo implements Constantes, Comparable{
static Random ran = new Random();
int numero, tiempo;
int[] tiempoCorredor = new int[POSTAS];
Equipo(int numero){
this.numero = numero+1;
}
void correr(){
for(int i=0; i<POSTAS; i++){
tiempoCorredor[i] = ran.nextInt(4)+10;
tiempo += tiempoCorredor[i];
}
}
public int compareTo(Object obj) {
Equipo eqi = (Equipo) obj;
if (tiempo < eqi.tiempo) return -1 ;
if (tiempo > eqi.tiempo) return 1 ;
return 0 ;
}
}