shushus

Спринт 1. Алгоритмы sort и reverse. Задание 1

Dec 3rd, 2022
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int count;
  10.     cin >> count;
  11.     vector<pair<int, string>> people;
  12.     for (int i = 0; i < count; ++i) {
  13.         string name;
  14.         int age;
  15.         cin >> name >> age;
  16.         people.push_back({age, name});
  17.         // сохраните в вектор пар
  18.     }
  19.     sort(people.begin(), people.end());
  20.     reverse(people.begin(), people.end());
  21.     for(auto& [age, name] : people){
  22.         cout<<name<<endl;
  23.     }
  24.     // выведите только имена в порядке убывания возраста
  25.     // Jack
  26.     // John
  27.     // ...
  28. }
Advertisement
Add Comment
Please, Sign In to add comment