fork download
  1. #include <iostream>
  2. #include <string>
  3. #include<algorithm>
  4. #include <map>
  5.  
  6. using namespace std;
  7. int main ()
  8. {
  9.  
  10. std::multimap<int,std::string> src{
  11. {1,"dwa"},
  12. {4,"dwa"},
  13. {1,"jeden"},
  14. {2,"jeden"},
  15. {5, "piec"}
  16. };
  17.  
  18. std::multimap<std::string,int> dst;
  19.  
  20. std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()),
  21. [] (const std::pair<int,std::string> &p) {
  22. return std::pair<std::string,int>(p.second, p.first);
  23.  
  24. }
  25. );
  26.  
  27.  
  28.  
  29. std::multimap<std::string,int>::iterator it = dst.begin();
  30.  
  31. for(int count = 0;it !=dst.end();++it,++count)
  32. std::cout<<it->first<<" "<<it->second<<std::endl;
  33.  
  34.  
  35. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
dwa 1
dwa 4
jeden 1
jeden 2
piec 5