Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- struct student{
- int id;
- int points;
- student(int i, int p)
- :id(i), points(p)
- {
- }
- };
- std::ostream& operator<<(std::ostream& out, const student& s)
- {
- out << s.id << " " << s.points;
- return out;
- }
- bool cmp_by_points(const student& s1, const student& s2)
- {
- if(s1.points != s2.points)
- return s1.points > s2.points;
- else
- return s1.id < s2.id;
- }
- template<class Iter>
- void print_container(Iter b, Iter e)
- {
- while(b != e)
- {
- cout << *b++ << endl;
- }
- }
- int main()
- {
- int n;
- cin >> n;
- vector<student> v;
- int id, pnts;
- for(int i = 0; i < n; ++i)
- {
- cin >> id >> pnts;
- v.push_back(student(id, pnts));
- }
- sort(v.begin(), v.end(), cmp_by_points);
- print_container(v.begin(), v.end());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement