标签:http class void integer exti system.in color entry entryset
import java.util.Map.Entry; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); TreeMap<Integer, Integer> map = new TreeMap<>(); int num = sc.nextInt(); for(int i=0;i<num;i++){ int key = sc.nextInt(); int value = sc.nextInt(); if(map.containsKey(key)){ map.replace(key, map.get(key) + value); }else { map.put(key, value); } } for(Entry<Integer, Integer> entry: map.entrySet()){ System.out.print(entry.getKey() + " "); System.out.println(entry.getValue()); } } }
标签:http class void integer exti system.in color entry entryset
原文地址:https://www.cnblogs.com/bopo/p/9259004.html