【Java】paizaレベルアップ問題集 > Cランクレベルアップメニュー > 辞書データの順序

おぼえがきです

import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ!!
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();
        HashMap<String, Integer> hoges = new HashMap<>();
        
        for(int i=0;i<num; i++){
            String name = sc.next();
            int damage = 0;
            hoges.put(name,damage);
        }
        
        
        int attack_num = sc.nextInt();
        
        for(int i=0; i<attack_num; i++){
            String hogestr = sc.next();
            int hogeint = sc.nextInt();
            
            int newhogeint = hoges.get(hogestr) + hogeint;
            hoges.put(hogestr,newhogeint);
            
        }
        
        
        ArrayList<String> keyList = new ArrayList<>(hoges.keySet());
        Collections.sort(keyList);

        for (String i : keyList) {
            System.out.println(hoges.get(i));
        }
        

    }
}

https://paiza.jp/works/mondai/c_rank_level_up_problems/c_rank_dictionary_step3

paiza問題集
0

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です