题解 | 合并表记录

合并表记录

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

#include <bits/stdc++.h>
#include <map>
using namespace std;

int main(){
    map<int, int> cur;
    int n;
    cin >> n;
    while (n--) {
        int l,r;
        cin >> l >> r;
        cur[l] += r;
    }
    for (auto it : cur)
        cout << it.first << ' ' << it.second << endl;

    return 0;
}

注意利用map特性,可以直接创建

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务