/* * 题目分析: 去重, 求和 * 解题思路: 直接用HashMap, 不过HashMap是无序的, 提交一次试试, 过不了换TreeMap * 知识记录: TreeMap 默认排序规则:按照key的字典顺序来排序(升序) * 提交失败: HashMap果然不行, 换TreeMap吧 */ import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); TreeMap<Integer, Integer> map = new TreeMap(); int count = sc.nextInt(); for (int i = 0; i < count; i++) { int key = sc.nextInt(); int val = sc.nextInt(); if (map.containsKey(key)) { val += map.get(key); } map.put(key, val); } for (Map.Entry<Integer, Integer> e: map.entrySet()) { System.out.println(e.getKey() + " " + e.getValue()); } } }