HDU OJ 1004

题目简单,仅供记录使用。

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int times = sc.nextInt();
HashMap map = new HashMap<>();
for (int i = 0; i < times; i++)
{
String color = sc.next();
if (map.containsKey(color))
map.put(color, map.get(color) + 1);
else
map.put(color, 1);
}
int max = 1;
for (Map.Entry e:
map.entrySet() ) {
if(e.getValue() > max)
max = e.getValue();
}
List l = new ArrayList<>();
for (Map.Entry e:
map.entrySet() ) {
if(e.getValue() == max)
l.add(e.getKey());
}
for (String s:
l) {
System.out.println(s);
}
}
}
}

你可能感兴趣的:(HDU OJ 1004)