fork download
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include <tuple>
  7. #include <vector>
  8.  
  9. struct Employee
  10. {
  11. unsigned id = 0;
  12. std::string first{};
  13. std::string last{};
  14. unsigned salary = 0;
  15. };
  16.  
  17. using EmployeeList = std::vector<Employee>;
  18.  
  19. int main(int, const char **)
  20. {
  21. EmployeeList list{};
  22. std::string line{};
  23.  
  24. while (std::getline(std::cin, line)) {
  25. std::stringstream ss{line};
  26.  
  27. Employee e{};
  28. ss >> e.id;
  29. ss >> e.first;
  30. ss >> e.last;
  31. ss >> e.salary;
  32.  
  33. list.push_back(std::move(e));
  34. }
  35.  
  36. std::sort(std::begin(list), std::end(list), [] (auto a, auto b) {
  37. return std::tie(a.last, a.salary) < std::tie(b.last, b.salary);
  38. });
  39.  
  40. for (const auto &e: list) {
  41. std::printf("%d - %s - %s - %d\n", e.id, e.first.c_str(), e.last.c_str(), e.salary);
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 16088KB
stdin
1000 George Washington 10000
2000 John Adams 15000
1212 Thomas Jefferson 34000
1313 Abraham Lincoln 45000
1515 Jimmy Carter 78000
1717 George Bush 80000
stdout
2000 - John - Adams - 15000
1717 - George - Bush - 80000
1515 - Jimmy - Carter - 78000
1212 - Thomas - Jefferson - 34000
1313 - Abraham - Lincoln - 45000
1000 - George - Washington - 10000