shushus

Спринт 1. Захват переменных по значению.

Dec 7th, 2022
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. string ReadLine() {
  10.     string s;
  11.     getline(cin, s);
  12.     return s;
  13. }
  14.  
  15. int ReadLineWithNumber() {
  16.     int result;
  17.     cin >> result;
  18.     ReadLine();
  19.     return result;
  20. }
  21.  
  22. int main() {
  23.     const int queryCount = ReadLineWithNumber();
  24.  
  25.     vector<string> queries(queryCount);
  26.     for (string& query : queries) {
  27.         query = ReadLine();
  28.     }
  29.     const string buzzword = ReadLine();
  30.  
  31.     cout << count_if(queries.begin(), queries.end(), [buzzword](const string& query) {
  32.         // Реализуйте эту лямбда-функцию
  33.         // Верните true, если query содержит слово buzzword
  34.         set<string> words;
  35.         string word;
  36.         for (const char c : query) {
  37.             if (c == ' ') {
  38.                 if (!word.empty()) {
  39.                     words.insert(word);
  40.                     word.clear();
  41.                 }
  42.             } else {
  43.                 word += c;
  44.             }
  45.         }
  46.         if (!word.empty()) {
  47.             words.insert(word);
  48.         }
  49.         return words.count(buzzword);
  50.        
  51.     });
  52.     cout << endl;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment