题解 | #合并表记录#

#include<iostream>
#include<map>
using namespace std;

int main()
{
	int n = 0;
	map<int, int> hash;
	cin >> n;
	int index, value;
	while (n)
	{
		cin >> index >> value;
		if (hash.count(index) == 0)
		{
			hash[index] = value;
		}
		else
		{
			hash[index] = hash[index] + value;
		}
		--n;
	}
	for (auto i : hash)
	{
		cout << i.first << " " << i.second << endl;
	}
	return 0;
}
全部评论

相关推荐

09-26 16:38
中南大学 营销
点赞 评论 收藏
分享
牛客83265014...:完了,连现在都没开始面,13号投的是不是晚了
秋招的第一个offer,...
点赞 评论 收藏
分享
08-05 15:59
已编辑
门头沟学院 运维工程师
哈哈哈,你是老六:感觉这女的就是把你当免费的劳动力
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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