Advertisement
chevengur

СПРИНТ №1 | Базовые алгоритмы | Урок 5: Алгоритм accumulate 2/2

Sep 6th, 2023 (edited)
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <set>
  2. #include <string>
  3. #include <numeric>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. string AddStopWords(const string& query, const set<string>& stop_words) {
  9.     return accumulate(stop_words.begin(), stop_words.end(), query, [](const string& result, const string& words) {
  10.         return result + " -" + words;
  11.     });
  12. }
  13.  
  14. int main() {
  15.     // Пример использования функции AddStopWords
  16.     set<string> stop_words = {};
  17.  
  18.     string query = "some tasty oranges";
  19.     string result = AddStopWords(query, stop_words);
  20.     cout << result << endl;  // Вывод: "Thisisthequery"
  21.  
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement