-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP186.java
66 lines (46 loc) · 1.14 KB
/
P186.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
package aceptaelreto;
import java.util.Scanner;
public class p186 {
static Scanner s;
public static void main (String args[]) {
s = new Scanner(System.in);
int[] teams;
int team,nteams,nglob,winner;
while (true) {
nteams = s.nextInt();
nglob = s.nextInt();
if(nteams == 0 && nglob == 0)break;
teams = init(nteams);
for(int i = 0;i < nglob;i++) {
team = s.nextInt();
s.next();
teams[team-1]++;
}
winner = getMax(teams);
System.out.println(winner == 0 ? "EMPATE" : winner);
}
}
static int getMax(int scores[]){
int maxValue = scores[0];
int index = 0;
boolean tie = false;
for(int i=1;i<scores.length;i++){
if(scores[i] > maxValue){
maxValue = scores[i];
index = i;
tie = false;
}else if(scores[i] == maxValue){
tie = true;
}
}
if(tie) return 0;
return index+1;
}
static int[] init(int team) {
int[] teams = new int[team];
for(int i = 0; i < team; i++) {
teams[i] = 0;
}
return teams;
}
}