题解 | #合并表记录#巧用TreeMap

合并表记录

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

import java.util.; import java.lang.; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); TreeMap<Integer,Integer> map=new TreeMap<Integer,Integer>(); for(int i=0;i<n;i++){ String[] line=sc.nextLine().split(" "); int a=Integer.parseInt(line[0]); int b=Integer.parseInt(line[1]); map.put(a,map.getOrDefault(a,0)+b); } for(Map.Entry<Integer,Integer> entry:map.entrySet()){ System.out.println(entry.getKey()+" "+entry.getValue()); } } }

全部评论

相关推荐

06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
码砖:求职岗位要突出,一眼就能看到,教育背景放到最后,学校经历没那么重要,项目要重点突出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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