fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8. string s1="hello";
  9.  
  10. std::vector<std::pair<std::string, std::pair<int, double> > > chromosomes;
  11. chromosomes.emplace_back(s1, std::make_pair(12, 0.202));
  12. chromosomes.emplace_back("good", std::make_pair(11, 0.202));
  13. chromosomes.emplace_back("bye", std::make_pair(14, 0.202));
  14. chromosomes.emplace_back("yep", std::make_pair(11, 0.204));
  15.  
  16. for (auto&x :chromosomes)
  17. cout <<x.first<<": "<<x.second.first<<" "<<x.second.second<<endl;
  18. cout<<endl;
  19.  
  20. sort(chromosomes.begin(), chromosomes.end(),
  21. [](auto &x, auto &y) { return x.second.first<y.second.first
  22. || (x.second.first==y.second.first
  23. && x.second.second<y.second.second );});
  24.  
  25. for (auto&x :chromosomes)
  26. cout <<x.first<<": "<<x.second.first<<" "<<x.second.second<<endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
hello: 12 0.202
good: 11 0.202
bye: 14 0.202
yep: 11 0.204

good: 11 0.202
yep: 11 0.204
hello: 12 0.202
bye: 14 0.202