/*multimap的个性:
允许重复key
元素是key/value对
不支持方括号下标
*/
#include <map>
#include <iostream>
using namespace std;
#include "print.h"
#include <string>
int main()
{
typedef multimap<string,double> MSD;
MSD m;
m.insert(MSD::value_type("WG",100000));
m.insert(make_pair("HJJ",120000));
m.insert(make_pair("YY",20000));
m.insert(make_pair("HJJ",160000));
m.insert(make_pair("YY",3000));
m.insert(MSD::value_type("WG",220000));
m.insert(MSD::value_type("WG",150000));
m.insert(make_pair("HJJ",130000));
m.insert(make_pair("YY",1000000));
m.insert(make_pair("YY",110000));
print(m.begin(), m.end());
MSD::iterator ib = m.begin(), ie;
MSD cnt;
while(ib!=m.end()){
string name = ib->first;
ie = m.upper_bound(name);
double sum = 0.0;
while(ib!=ie) sum += ib++->second;
cnt.insert(make_pair(name,sum*0.03));
}
print(cnt.begin(),cnt.end());
}
/*
输出:
HJJ:120000 HJJ:160000 HJJ:130000 WG:100000 WG:220000 WG:150000 YY:20000 YY:3000 YY:1e+06 YY:110000
HJJ:12300 WG:14100 YY:33990 */
c++ STL之 multimap 的个性(权哥)
最新推荐文章于 2022-07-29 17:12:29 发布