解题思路:
注意事项:
参考代码:
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二级辅导-分段函数 (C语言代码)浏览:580 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:442 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:922 |
C二级辅导-阶乘数列 (C语言代码)浏览:732 |
WU-格式化数据输出 (C语言代码)浏览:1813 |
WU-printf基础练习2 (C++代码)浏览:2047 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:566 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:640 |
【计算直线的交点数】 (C语言代码)浏览:1490 |