题解 | #合并表记录#使用map自带排序

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

int main() {
     int num;
     cin >> num;

     map<int, int> map_list;
     for (int i = 0; i < num; ++i) {
        int index, value;
        cin >> index >> value;
        map_list[index] += value;
     }

     for (auto it = map_list.begin(); it != map_list.end(); ++it)
        cout << it->first << " " << it->second << endl;

    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
转发
投递拼多多等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务