-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrecount.java
35 lines (32 loc) · 1.19 KB
/
recount.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
import java.io.*;
import java.util.*;
public class recount {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
HashMap<String, Integer> votes = new HashMap<String, Integer>();
while(true) {
String line = in.readLine();
if(line.equals("***")) break;
if(votes.get(line) == null) {
votes.put(line, 1);
}
else {
votes.put(line, votes.get(line) + 1);
}
}
ArrayList<Integer> list = new ArrayList<Integer>();
int max = Integer.MIN_VALUE;
String winner = "";
for(Map.Entry<String, Integer> entry : votes.entrySet()) {
if(max < entry.getValue()) {
max = entry.getValue();
winner = entry.getKey();
}
list.add(entry.getValue());
}
boolean runoff = Collections.frequency(list, max) != 1;
out.println(runoff ? "Runoff!" : winner);
out.close();
}
}