fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. bool sortowanie(const pair<int,int> &p1,const pair<int,int> &p2)
  6. {
  7. if(p1.first != p2.first)
  8. return p2.first < p1.first;
  9. else
  10. return p2.second > p1.second;
  11. }
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);
  16. cout.tie(0);
  17.  
  18. int ilosc_towarow;
  19. cin>>ilosc_towarow;
  20. vector<pair<int,int>> towar(ilosc_towarow);
  21.  
  22. for(int i=0;i<ilosc_towarow;i++)
  23. cin>>towar[i].second>>towar[i].first;
  24.  
  25. sort(towar.begin(),towar.end(),sortowanie);
  26.  
  27. for(int i=0;i<ilosc_towarow;i++)
  28. cout<<towar[i].second<<' '<<towar[i].first<<endl;
  29. }
Success #stdin #stdout 0.01s 5280KB
stdin
8
2 3
1 8
4 6
4 4
6 4
7 3
8 1
6 4 
stdout
1 8
4 6
4 4
6 4
6 4
2 3
7 3
8 1