合并记录
合并表记录
http://www.nowcoder.com/questionTerminal/de044e89123f4a7482bd2b214a685201
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); TreeMap<Integer, Integer> map = new TreeMap<>(); // 输出结果要求有序! while(sc.hasNextInt()){ int n = sc.nextInt(); for(int i = 0; i < n; ++i){ int a = sc.nextInt(); int b = sc.nextInt(); map.put(a,map.getOrDefault(a,0) + b); } } for (Integer i : map.keySet()) { System.out.println(i + " " + map.get(i)); } } }