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

合并表记录

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;
}
全部评论

相关推荐

点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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