Last active
August 29, 2015 13:57
-
-
Save ramntry/9772110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gosha Vasechkin 22 10000
Vasya Pupkin 19 5000
Maria Kushnir 21 7000
Ivan Ivanovich 37 17000
Petr Kuzmenko 31 15000