Guest User

Untitled

a guest
Dec 14th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<algorithm>
  2. #include<vector>
  3. #include<iostream>
  4.  
  5. using namespace std;
  6.  
  7. bool comp(pair<int, int> a, pair<int, int> b){
  8.  
  9. if(a.first<b.first){
  10. return 1;
  11. }else if(a.second<b.second && a.first==b.first)
  12. return 1;
  13.  
  14. return 0;
  15.  
  16. }
  17.  
  18. int main(){
  19.  
  20. int x[]={7, 2, 2, 9, 5};
  21. vector<int> a(x, x+sizeof(x)/sizeof(int));
  22.  
  23. int y[]={2,5, 1, 5, 4};
  24. vector<int> b(y, y+sizeof(y)/sizeof(int));
  25.  
  26. vector<pair<int, int> > p;
  27.  
  28. for(int i=0; i<a.size(); i++){
  29. pair<int, int> m;
  30. m.first=a[i];
  31. m.second=b[i];
  32. p.push_back(m);
  33. }
  34.  
  35. sort(p.begin(), p.end(), comp);
  36.  
  37. for(int i=0; i<p.size(); i++){
  38. cout<<p[i].first<<' '<<p[i].second<<'\n';
  39. }
  40.  
  41.  
  42. }
Add Comment
Please, Sign In to add comment