题解 | #合并表记录#

合并表记录

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

while True: try: n = int(input()) #创建散列表 table = dict() #将数据加入散列表 for i in range(n): list1 = input().split(" ") #如果已存在键,则在原值上加现值 if(int(list1[0]) in table.keys()): table[int(list1[0])] += int(list1[1]) #不存在键,则新建键值对 else: table[int(list1[0])] = int(list1[1]) #将键排序后打印 for k in sorted(table.keys()): print(k,end=(' ')) print(table.get(k)) except(EOFError,ValueError): break

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:47
机械打工仔:你自己匿名可以,这么好的公司就别给它匿名了
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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