题解 | #合并表记录#

合并表记录

http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201

题目 合并表记录

日期:2022/03/16

思路

利用TreeMap排序的特性

代码

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<Integer,Integer> map = new TreeMap<>();
        int times = sc.nextInt();
        for(int i=0;i<times;i++){
            int key = sc.nextInt();
            int value = sc.nextInt();
            map.put(key,map.getOrDefault(key,0)+value);
        }
        for(Integer i : map.keySet())
            System.out.println(i+" "+map.get(i));
    }
}
全部评论

相关推荐

爱睡觉的冰箱哥:学历不够啊兄弟,分析师都是9硕✌🏻咱搞不过他们滴
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-28 12:15
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务