Skip to content

Instantly share code, notes, and snippets.

@ramntry
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramntry/9772110 to your computer and use it in GitHub Desktop.
Save ramntry/9772110 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
struct Employer {
std::string firstname;
std::string lastname;
double age;
double salary;
};
std::istream &operator >>(std::istream &in, Employer &e) {
return in >> e.firstname >> e.lastname >> e.age >> e.salary;
}
std::ostream &operator <<(std::ostream &out, Employer const &e) {
return out << e.firstname << ' ' << e.lastname << ' ' << e.age << ' ' << e.salary;
}
int main() {
std::vector<Employer> employers;
copy(std::istream_iterator<Employer>(std::cin),
std::istream_iterator<Employer>(),
back_inserter(employers));
sort(employers.begin(), employers.end(), [](Employer const &lhs, Employer const &rhs) {
return rhs.salary < lhs.salary;
});
copy(employers.begin(), employers.end(), std::ostream_iterator<Employer>(std::cout, "\n"));
}
@ramntry
Copy link
Author

ramntry commented Mar 25, 2014

Gosha Vasechkin 22 10000
Vasya Pupkin 19 5000
Maria Kushnir 21 7000
Ivan Ivanovich 37 17000
Petr Kuzmenko 31 15000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment