RobertDeMilo

Основы С++2.4 Алгоритмы sort и reverse / Задача 1

Sep 23rd, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <utility>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     vector<pair<int, string>> people;
  11.  
  12.     int count;
  13.     cin >> count;
  14.     for (int i = 0; i < count; ++i) {
  15.         string name;
  16.         int age;
  17.         cin >> name >> age;
  18.         people.push_back({age, name});
  19.     }
  20.  
  21.     sort(people.begin(), people.end());
  22.     reverse(people.begin(), people.end());
  23.  
  24.     for (const auto& person : people) {
  25.         cout << person.second << endl;
  26.     }
  27. }
Tags: Reverse sort
Add Comment
Please, Sign In to add comment