Advertisement
chevengur

СПРИНТ № 2 | Числовые типы | Урок 6: Техника безопасности

Oct 9th, 2023 (edited)
399
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.     int rating;
  10. };
  11.  
  12. void PrintDocuments(vector<Document> documents, size_t skip_start, size_t skip_finish) {
  13.     if(documents.empty() || skip_start >= documents.size() || skip_finish >= documents.size()){
  14.         return;
  15.     }
  16.     sort(documents.begin(), documents.end(), [](Document& first, Document& second){
  17.         return first.rating > second.rating;
  18.     });
  19.  
  20.     for(size_t start = skip_start; start + skip_finish < documents.size(); ++start){
  21.         cout << "{ id = " << documents[start].id << ", rating = "  << documents[start].rating << " }" << endl;
  22.     }
  23. }
  24.  
  25. int main() {
  26.     PrintDocuments({{100, 5}, {101, 7}, {102, -4}, {103, 9}, {104, 1}}, 1, 2);
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement