解题思路:
注意事项:
参考代码:
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++代码)浏览:1032 |
矩形面积交 (Java代码)浏览:1239 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1456 |
分糖果 (C++代码)浏览:1468 |
【绝对值排序】 (C++代码)浏览:695 |
简单的a+b (C语言代码)浏览:550 |
C语言训练-求函数值 (C语言代码)浏览:586 |
C语言训练-求PI* (C语言代码)浏览:617 |
【矩阵】 (C++代码)浏览:962 |