题解 | #合并表记录#

合并表记录

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String num = in.nextLine();
            TreeMap<Integer, Integer> m = new TreeMap<>();
            for (int i = 0; i < Integer.valueOf(num); i++) {
                String str = in.nextLine();
                String[] arr = str.split(" ");
                if (null == m.get(Integer.valueOf(arr[0]))) {
                    m.put(Integer.valueOf(arr[0]), Integer.valueOf(arr[1]));
                } else {
                    m.put(Integer.valueOf(arr[0]),
                          Integer.valueOf(arr[1]) + m.get(Integer.valueOf(arr[0])));
                }
            }
            for (Map.Entry<Integer, Integer> e : m.entrySet()) {
                System.out.println(e.getKey() + " " + e.getValue());
            }
        }
    }
}

全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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