打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
multimap的使用方法和举例

multimap的使用方法和举例

 

 

#include <iostream>
#include<map>
#include<string>

using namespace std;

typedef struct Info
{
    string Name;
    int Num;
    int Age;
};

int main()
{
    multimap<string,Info> match;
    multimap<int,Info> forMatch;
    string name1;
    multimap<string,Info>::iterator it;
    multimap<int,Info>::iterator it1;
    pair< multimap<string,Info>::iterator, multimap<string,Info>::iterator> ret;
    Info info1,info2,info0;
    int N;
    cin>>N;
    for (int i=0; i<N; i++)
    {
        cin>>name1>>info0.Name>>info0.Num>>info0.Age;
        match.insert(pair<string,Info>(name1,info0));
    }
    cin>>N;
    string Str;
    cin>>Str;
    int toKey=0;
    ret=match.equal_range(Str);
    for (it=ret.first; it!=ret.second; ++it)
    {
        toKey=(*it).second.Num;
        (*it).second.Num=1;
        forMatch.insert(pair<int,Info>(toKey,(*it).second));
    }
    for (int i=1; i<N; i++)
    {
        cin>>Str;
        ret=match.equal_range(Str);
        for(it1=forMatch.begin(); it1!=forMatch.end(); ++it1)
        {
            for (it=ret.first; it!=ret.second; ++it)
            {
                if (((*it).second.Name==(*it1).second.Name)&&((*it).second.Num==(*it1).first)&&((*it).second.Age==(*it1).second.Age))
                    (*it1).second.Num++;
            }
        }
    }
    for(it1=forMatch.begin(); it1!=forMatch.end(); ++it1)
    {
        if ((*it1).second.Num>=N)
            cout<<(*it1).second.Name<<" "<<(*it1).first<<" "<<(*it1).second.Age<<endl;
    }
    return 0;
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
上千万或上亿数据(有反复),统计当中出现次数最多的N个数据. C++实现
map以及使用举例--C++基础
c++中map的嵌套用法
C++Primer 学习笔记之关联容器
标准模板库(STL)学习探究之Multimap容器
java常用集合类详解(有例子,集合类糊涂的来看!) .
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服