1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <map>
using namespace std;
int main()
{
multimap<string,int> mm;
mm.insert(pair<string,int>("3",3));
mm.insert(pair<string,int>("4",4));
mm.insert(pair<string,int>("4",4));
mm.insert(pair<string,int>("5",5));
mm.insert(pair<string,int>("5",5));
mm.insert(pair<string,int>("6",6));
mm.insert(pair<string,int>("6",6));
mm.insert(pair<string,int>("7",7));
mm.insert(pair<string,int>("8",8));
mm.insert(pair<string,int>("9",9));
mm.insert(pair<string,int>("9",9));
mm.insert(pair<string,int>("10",10));
multimap<string,int>::iterator it2=mm.begin();
it2++;
for(multimap<string,int>::iterator it1=mm.begin() ; it1 != mm.end() ; it1++)
{
while(it1->second == it2->second)
{
mm.erase(it2);
it2 = it1;
it2++;
}
it2++;
}
for(multimap<string,int>::iterator it=mm.begin() ; it != mm.end() ;it++)
{
cout << (*it).first << "=>" << (*it).second << endl;
}
return 0;
}
|