杭电1004

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
package oj;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main_1004 {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int n = scanner.nextInt();
if (n == 0) {
break;
}
Map<String,Integer> map=new HashMap<String, Integer>();
scanner.nextLine();
for (int j = 0; j < n; j++) {
String color=scanner.nextLine();
if (map.containsKey(color)) {
int m=map.get(color);
m++;
map.put(color, m);
}else{
map.put(color, 1);
}

}
int max=0;
String maxString="";

for (Map.Entry<String,Integer> entry : map.entrySet()) {
if (entry.getValue()>max) {
max=entry.getValue();
maxString=entry.getKey();
}
}
System.out.println(maxString);
}

}

}