华为题库 HJ8 合并表记录

HJ8 合并表记录

在这里插入图片描述

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

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

    for(auto it:myMap)
    {
    
    
        cout<<it.first<<' '<<it.second<<endl;
    }
}
// 64 位输出请用 printf("%lld")

猜你喜欢

转载自blog.csdn.net/qq_44814825/article/details/130051584