Advertisement
chevengur

СПРИНТ № 2 | Пары и кортежи | Урок 2: Улучшаем сравнение

Oct 12th, 2023 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 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 (lhs.rating > rhs.rating) || (lhs.relevance > rhs.relevance);
  17.          });
  18. }
  19.  
  20. int main() {
  21.     vector<Document> documents = {{100, 0.5, 4}, {101, 1.2, 4}, {102, 0.3, 5}};
  22.     SortDocuments(documents);
  23.     for (const Document& document : documents) {
  24.         cout << document.id << ' ' << document.relevance << ' ' << document.rating << endl;
  25.     }
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement