-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGanador.java
74 lines (61 loc) · 1.73 KB
/
Ganador.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.Arrays;
/**
* Y el ganador es ...
* El ejercicio 186
*
* @author JCHacking
* @version 20.11.2020
*/
public class Ganador{
static java.util.Scanner sc;
public static void main(String[] args){
sc = new java.util.Scanner(System.in);
while(sc.hasNext()){
int numeroEquipos = sc.nextInt();
int numeroGlobos = sc.nextInt();
sc.nextLine();
int[] globosEquipo = new int[numeroEquipos];
//SI ES 0 0
if(numeroEquipos == 0 && numeroGlobos == 0)
break;
//CONTAR GLOBOS POR EQUIPO
for(int globo = 0; globo < numeroGlobos; globo++){
String linea = sc.nextLine();
int separacion = linea.indexOf(" ");
String numeroStr = linea.substring(0, separacion);
int equipo = Integer.parseInt(numeroStr);
globosEquipo[equipo - 1] += 1;
}
//Encontrar el mayor indice
if(numeroEquipos > 1){
int indiceMayor = 0;
int indiceMayorSiguiente = 1;
if(globosEquipo[indiceMayor] < globosEquipo[indiceMayorSiguiente]){
indiceMayor = 1;
indiceMayorSiguiente = 0;
}
if(numeroEquipos > 2){
for(int equipo = 2; equipo < numeroEquipos; equipo++){
int numeroGlobosEquipoActual = globosEquipo[equipo];
if(numeroGlobosEquipoActual > globosEquipo[indiceMayor]){
indiceMayorSiguiente = indiceMayor;
indiceMayor = equipo;
}else if(numeroGlobosEquipoActual > globosEquipo[indiceMayorSiguiente]){
indiceMayorSiguiente = equipo;
}
}
}
boolean empate = false;
if(globosEquipo[indiceMayor] == globosEquipo[indiceMayorSiguiente])
empate = true;
if(empate){
System.out.println("EMPATE");
}else{
System.out.println(indiceMayor + 1);
}
}else{
System.out.println(1);
}
}
}
}