Advertisement
7oSkaaa

Sorting pairs

Aug 18th, 2021
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC optimize("Ofast")
  3. #pragma GCC target("avx,avx2,fma,sse,sse2,sse3,sse4")
  4. using namespace std;
  5.  
  6. #define cin(vec) for(auto& i : vec) cin >> i
  7. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  8. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  9. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  10. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  11. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  12. #define fixed(n) fixed << setprecision(n)
  13. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define fill(vec, value) memset(vec, value, sizeof(vec));
  15. #define Num_of_Digits(n) ((int)log10(n)+1)
  16. #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
  17. #define all(vec) vec.begin(),vec.end()
  18. #define rall(vec) vec.rbegin(),vec.rend()
  19. #define sz(x) int(x.size())
  20. #define TC int t; cin >> t;   while(t--)
  21. #define fi first
  22. #define se second
  23. #define Pair pair < int, int >
  24. #define ll long long
  25. #define ull unsigned long long
  26. #define Mod  1'000'000'007
  27. #define OO 2'000'000'000
  28. #define EPS 1e-9
  29. #define PI acos(-1)
  30.  
  31. void AhMeD_HoSSaM(){
  32.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  33.   #ifndef ONLINE_JUDGE
  34.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  35.   #endif
  36. }
  37.  
  38. bool comp(pair < string, int > a, pair < string, int > b){
  39.   if(a.se == b.se) return a.fi < b.fi;
  40.   else return a.se > b.se;
  41. }
  42.  
  43. int main(){
  44.   AhMeD_HoSSaM();
  45.   int n;
  46.   cin >> n;
  47.   vector < pair < string, int > > emp(n);
  48.   for(auto& [name, salary] : emp) cin >> name >> salary;
  49.   sort(all(emp), comp);
  50.   for(auto& [name, salary] : emp) cout << name << " " << salary << "\n";
  51.   Time
  52.   return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement