勉强ac,时间和空间还有待优化~
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
if (n == 0)
break;
String[] colors = new String[n];
int[] count = new int[n];
while ((n--) > 0) {
colors[n] = sc.next();
for (int i = colors.length - 1; i > n; --i) {
if (colors[i].equals(colors[n])) {
++(count[i]);
}
}
}
int index = 0;
for (int i = 1; i < count.length; i++) {
if (count[i] > count[index]) {
index = i;
}
}
list.add(colors[index]);
}
for (String s : list) {
System.out.println(s);
}
}
}