fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. bool comp(const std::pair<float, std::string>&a, const std::pair<float, std::string>&b){
  8. if(a.first == b.first) return 0;
  9. else return a.first < b.first;
  10. }
  11.  
  12. int main()
  13. {
  14. std::vector<std::pair<float, std::string>> vec;
  15. vec = {{1, "e"}, {1, "d"}, {1, "c"}, {1, "b"}, {1, "a"}};
  16. std::sort(vec.begin(), vec.end(), comp);
  17. for (auto i : vec)
  18. std::cout << i.first << ", " << i.second << '\n';
  19. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1, e
1, d
1, c
1, b
1, a