解题思路:
注意事项:
参考代码:
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 人评分
【绝对值排序】 (C语言代码)浏览:484 |
C语言考试练习题_排列 (C++代码)浏览:646 |
简单的a+b (C语言代码)浏览:651 |
Hello, world! (C语言代码)浏览:1261 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:473 |
矩阵乘法 (C++代码)浏览:1505 |
用筛法求之N内的素数。 (C语言代码)浏览:1285 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:894 |
【计算球体积】 (C语言代码)浏览:1128 |
1642题解浏览:723 |