题解 | #合并表记录#

合并表记录

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

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

int main() {
    map<int, int>umap;
    int n;
    cin >> n;
    int key, value;
    while (n--) {
        cin >> key >> value;
        umap[key] += value;
    }
    for (auto& it : umap) {
        cout << it.first << " " << it.second << endl;
    }
}

数据量应该是改了,不能直接用数组做hashtable

全部评论

相关推荐

05-12 17:28
已编辑
门头沟学院 硬件开发
ldf李鑫:不说公司名祝你以后天天遇到这样的公司
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务