解题思路:
注意事项:
参考代码:
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(); if (times == 0){ break; } Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < times; i++) { String balloon = sc.next(); if (map.containsKey(balloon)) { map.put(balloon, map.get(balloon) + 1); } else { map.put(balloon, 1); } } int max = 0; String balloon = ""; for (Map.Entry<String, Integer> b: map.entrySet()) { // 大于等于的话会允许后面的覆盖前面的 if (b.getValue() >= max){ max = b.getValue(); balloon = b.getKey(); } } System.out.println(balloon); } } }
0.0分
0 人评分