fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n;
  9. while (cin >> n){
  10. map<string, int> mp;
  11. for (int i = 0; i < n; i++) {
  12. string mt;
  13. int val;
  14. cin >> mt >> val;
  15. mp[mt] = val;
  16. }
  17. vector<pair<string, int>> vt;
  18. for (auto it : mp)
  19. vt.push_back(it);
  20. sort(vt.begin(), vt.end(), [](pair<string, int> a, pair<string, int> b) {
  21. if (a.second != b.second)
  22. return a.second < b.second;
  23. return a.first < b.first;
  24. });
  25. for (int i = 0; i < n; i++)
  26. cout << vt[i].first << " \n"[i == n - 1];
  27. }
  28. }
Success #stdin #stdout 0s 544KB
stdin
3

picanha 15

coracao 14

maminha 37

4

alcatra 17

linguica 13

asinha 5

pernil 23
stdout
coracao picanha maminha
asinha linguica alcatra pernil