首页 > 其他 > 详细

1004.Let the Balloon Rise

时间:2019-07-08 13:55:08      阅读:92      评论:0      收藏:0      [点我收藏+]

技术分享图片
因为一开始做这道题的时候 采用的是 自己写一个方法 然后方法实现功能 结果搞得自己一直都没有运行成功
好吧~~~ I am fine

import java.util.*;
import java.util.Map.Entry;
 
public class Main {
//我的话 说一下思路
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//      构造一个hashmap 存放数据 就简单使用map 的方法 
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        while (sc.hasNext()) {
            int num = sc.nextInt();
            if (num == 0)
                break;
            hm.clear();
            for (int i = 0; i < num; i++) {
                String str = sc.next();
                if (!hm.containsKey(str)) {
                    hm.put(str, 1);
                } else {
                    hm.put(str, hm.get(str) + 1);
                }
            }
            int temp = 0;
            String string = "";
//最主要是map的遍历
            for (Entry<String, Integer> entry : hm.entrySet()) {
                if (entry.getValue() > temp) {
                    temp = entry.getValue();
                    string = entry.getKey();
                }
            }
            System.out.println(string);
        }
    }
}

1004.Let the Balloon Rise

原文:https://www.cnblogs.com/cznczai/p/11150160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!