• 1004.Let the Balloon Rise



    因为一开始做这道题的时候 采用的是 自己写一个方法 然后方法实现功能 结果搞得自己一直都没有运行成功
    好吧~~~ 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);
    		}
    	}
    }
    
  • 相关阅读:
    Codeforces Round #319 (Div. 2) D
    因为网络请求是 异步的,
    ios真蛋疼,
    单例模式的两种实现,
    jump, jump,
    一点 误删,
    关于代理,
    button上的两个手势,
    数据,
    header 的蓝色,
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150160.html
Copyright © 2020-2023  润新知