题解 | #合并表记录#

合并表记录

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

#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

int main (){
    unsigned N;
    while(cin>>N){
        int index,value;
        map<int,int> mapi;
        while(cin>>index>>value){
            
            auto rsultpair = mapi.insert(pair<int,int>(index,value));
            if(!rsultpair.second){
                mapi[index]=mapi[index]+value;
            }
            
            N--;
            if(N==0)break;
        }
        auto it = mapi.cbegin();
        while(it!=mapi.cend()){
            cout<<it->first<<' '<<it->second<<endl;
            it++;
        }
        
        
    }
    
}
全部评论

相关推荐

zaakfung:26届不应该春招吗 为啥还实习
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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