nrk009

PAIRSTL

Aug 2nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. /*i am not gonna
  2. lose this time*/
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
  8.  
  9. #define ll long long
  10. #define ull unsigned long long
  11. #define INF INT_MAX
  12. #define INM INT_MIN
  13.  
  14. #define mp make_pair
  15. #define pb push_back
  16. #define lb lower_bound
  17. #define ub upper_bound
  18. #define F first
  19. #define S second
  20.  
  21. #define st(x) x.begin(),x.end()
  22. #define sz(x) (int)(x).size()
  23. #define bitcount(x) __builtin_popcountll(x)
  24.  
  25. #define f(i,n) for(int i=0;i<n;i++)
  26. #define f1(i,n) for(int i=1;i<=n;i++)
  27.  
  28. int main()
  29. {
  30.     fast;
  31.     /* pair <string,double> PAIR2  ("GeeksForGeeks", 1.23);
  32.       cout << PAIR2.first << " " ;
  33.     cout << PAIR2.second << endl ;
  34.  
  35.      PAIR3 = make_pair ("GeeksForGeeks is Best",4.56);
  36.       g2.first = ".com";
  37.     g2.second = 2;
  38.  
  39.     pair <string, int> g3(g2);*/
  40.  
  41.      pair<ll,ll>ar[n];  //declaration of pair of array;
  42.      vector<pair<int,int>>v(n);  //declaration of pair of vectors
  43.  
  44.   for(int i=0;i<n;i++){
  45.   cin>>a>>b;
  46.   ar[i].first=a;
  47.   ar[i].second=b;
  48.    v[i]=make_pair(a,b);
  49.    v[i]={a,b};
  50.   v.push_back(make_pair(a,b));
  51.   }
  52.  
  53.  vector<pair<int,int>>v{{1,2},{2,3}};
  54.  //PRINTING VECTOR AND ARRAY PAIRS
  55. vector<pair<int,int>>::iterator it;
  56.  
  57. for(it=v.begin();it!=v.end();it++)
  58. cout<<it->first<<" "<<it->second<<" ";
  59.  
  60.  for(auto it:v)
  61.  cout<<it.first<<" "<<it.second<<" ";
  62.  
  63.  for(auto i=0;i<v.size();i++)
  64.  cout<<v[i].first<<" "<<v[i].second<<" ";
  65.  
  66.  for(int i=0;i<n;i++){
  67.         cout<<ar[i].first<<"  ";
  68.         cout<<ar[i].second<<" ";
  69.  }
  70.  
  71.      pair1.swap(pair2); //swap pair values
  72.  
  73. //SORT PAIR
  74. sort(v.begin(),v.end());  //sort by first elements
  75. sort(v.begin(),v.end(),sortbysec);
  76. bool sortbysec(pair<int,int> a,pair<int,int> b)
  77. {
  78.         return b.second>a.second;
  79. }
  80.  
  81.  
  82.   return 0;
  83. }
Add Comment
Please, Sign In to add comment