题解 | #求长方体表面积#

合并表记录

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

#include<bits/stdc++.h>
//键值对且存在相同的键
using namespace std;
int main(){
    int num,index,value;
    cin>>num;
    multimap<int, int> mymmap;//允许存在相同的键
    map<int,int> mymap;//键唯一
    //解析输入并导入multimap
    while(cin>>index>>value){
        mymmap.insert(pair<int, int>(index,value));
    }
    //将mymmap里的数据按指定规则导入mymap
    for(auto m:mymmap){
        if (mymmap.count(m.first)!=1){//如果存在相同的键
            int temp = 0;
            auto pairfound = mymmap.find(m.first);//找出所有该键值的键值对
            for(size_t counter = 0; counter<mymmap.count(m.first); ++counter){
                temp += pairfound->second;//取和
                ++pairfound;//下一个
            }
            mymap.insert(pair<int, int>(m.first,temp));//导入mymap
        }
        else{//如果改键仅有一个
            mymap.insert(pair<int,int>(m.first,m.second));//直接导入mymap
        }
    }
    for(auto m:mymap){//输出
        cout<<m.first<<" "<<m.second<<endl;
    }
    return 0;
}
全部评论

相关推荐

昨天 18:09
门头沟学院 Java
苍穹外卖和谷粒商城这俩是不是烂大街了,还能做吗?
想去重庆的鸽子在吐槽:你不如把这俩做完自己搞明白再优化点再来问 何必贩卖焦虑
点赞 评论 收藏
分享
牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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