prizrak567890

Урок 3. Пары в компараторах / Задача 1 / Спринт 2

Oct 24th, 2023 (edited)
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct Document {
  8.     int id;
  9.     double relevance;
  10.     int rating;
  11. };
  12.  
  13. void SortDocuments(vector<Document>& matched_documents) {            
  14.     sort(matched_documents.begin(), matched_documents.end(),
  15.          [](const Document& lhs, const Document& rhs) {
  16.              return
  17.                  pair(lhs.rating, lhs.relevance)
  18.                   > pair(rhs.rating, rhs.relevance);
  19.          });
  20. }
  21. int main() {
  22.     vector<Document> documents = {{100, 0.5, 4}, {101, 1.2, 4}, {102, 0.3, 5}};
  23.     SortDocuments(documents);
  24.     for (const Document& document : documents) {
  25.         cout << document.id << ' ' << document.relevance << ' ' << document.rating << endl;
  26.     }
  27.  
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment