Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<algorithm>
- #include<vector>
- #include<iostream>
- using namespace std;
- bool comp(pair<int, int> a, pair<int, int> b){
- if(a.first<b.first){
- return 1;
- }else if(a.second<b.second && a.first==b.first)
- return 1;
- return 0;
- }
- int main(){
- int x[]={7, 2, 2, 9, 5};
- vector<int> a(x, x+sizeof(x)/sizeof(int));
- int y[]={2,5, 1, 5, 4};
- vector<int> b(y, y+sizeof(y)/sizeof(int));
- vector<pair<int, int> > p;
- for(int i=0; i<a.size(); i++){
- pair<int, int> m;
- m.first=a[i];
- m.second=b[i];
- p.push_back(m);
- }
- sort(p.begin(), p.end(), comp);
- for(int i=0; i<p.size(); i++){
- cout<<p[i].first<<' '<<p[i].second<<'\n';
- }
- }
Add Comment
Please, Sign In to add comment