HJ8.合并表记录

合并表记录

https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201?tpId=37&tags=&title=&difficulty=&judgeStatus=&rp=1&gioEnter=menu

HJ8.合并表记录

#include <iostream>
#include <map>

int main() {
    int num = 0;
    int key = 0, val = 0;
    std::map<int, int> dict;
    std::cin >> num;
    for (int i = 0; i < num; ++i) {
        std::cin >> key >> val;
        dict[key] += val;
    }
    for (auto& i : dict) {
        std::cout << i.first << ' ' << i.second << '\n';
    }
    return 0;
}

解题思路

难点1:map就可以了

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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